add basic Users- and SeminariesAgent

This commit is contained in:
coderkun 2014-01-17 16:26:49 +01:00
commit 150aa2d1b5
13 changed files with 470 additions and 5 deletions

View 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 registered seminaries.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class SeminariesAgent extends \nre\agents\IntermediateAgent
{
/**
* Action: index.
*/
public function index(\nre\core\Request $request, \nre\core\Response $response)
{
}
}
?>

View 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 registered users and their data.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class UsersAgent extends \nre\agents\IntermediateAgent
{
/**
* Action: index.
*/
public function index(\nre\core\Request $request, \nre\core\Response $response)
{
}
}
?>

View file

@ -56,7 +56,9 @@
* @var array
*/
public static $routes = array(
array('css/?(.*)', 'css/$1?layout=stylesheet', false)
array('css/?(.*)', 'css/$1?layout=stylesheet', false),
array('users/(.+)', 'users/user/$1', false),
array('seminaries/(.+)', 'seminaries/seminary/$1', false)
);
@ -67,7 +69,22 @@
* @var array
*/
public static $reverseRoutes = array(
//array('<pattern>', '<replace>', '<is_last>')
array('users/user/(.*)', 'users/$1', false),
array('seminaries/seminary/(.*)', 'seminaries/$1', false)
);
/**
* Database connection settings
*
* @static
* @var array
*/
public static $database = array(
'user' => 'z',
'host' => 'localhost',
'password' => 'legendofZ',
'db' => 'z'
);
}

View file

@ -0,0 +1,75 @@
<?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 Agent to list registered seminaries.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class SeminariesController extends \hhu\z\Controller
{
/**
* Required models
*
* @var array
*/
public $models = array('seminaries', 'users');
/**
* Action: index.
*
* List registered seminaries.
*/
public function index()
{
// Get seminaries
$seminaries = $this->Seminaries->getSeminaries();
// Get additional data
foreach($seminaries as &$seminary)
{
// Created user
$seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
}
// Pass data to view
$this->set('seminaries', $seminaries);
}
/**
* Action: seminary.
*
* Show a seminary and its details.
*
* @throws IdNotFoundException
* @param string $seminaryUrl URL-Title of a seminary
*/
public function seminary($seminaryUrl)
{
// Get seminary
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
// Pass data to view
$this->set('seminary', $seminary);
}
}
?>

View file

@ -0,0 +1,61 @@
<?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 Agent to list registered users and their data.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class UsersController extends \hhu\z\Controller
{
/**
* Action: index.
*/
public function index()
{
// Get registered users
$users = $this->Users->getUsers();
// Pass data to view
$this->set('users', $users);
}
/**
* Action: user.
*
* Show a user and its details.
*
* @throws IdNotFoundException
* @param string $userUrl URL-Username of an user
*/
public function user($userUrl)
{
// Get user
$user = $this->Users->getUserByUrl($userUrl);
// Pass data to view
$this->set('user', $user);
}
}
?>

104
models/SeminariesModel.inc Normal file
View file

@ -0,0 +1,104 @@
<?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 SeminariesAgent to list registered seminaries.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class SeminariesModel extends \hhu\z\Model
{
/**
* Construct a new SeminariesModel.
*/
public function __construct()
{
parent::__construct();
}
/**
* Get registered seminaries.
*
* @return array Seminaries
*/
public function getSeminaries()
{
// Get seminaries
return $this->db->query(
'SELECT id, created, created_user_id, title, url '.
'FROM seminaries '.
'ORDER BY created DESC'
);
}
/**
* Get a seminary and its data by its ID.
*
* @throws IdNotFoundException
* @param string $seminaryId ID of a seminary
* @return array Seminary
*/
public function getSeminaryById($seminaryId)
{
$seminary = $this->db->query(
'SELECT id, created, created_user_id, title, url '.
'FROM seminaries '.
'WHERE id = ?',
'i',
$seminaryId
);
if(empty($seminary)) {
throw new \nre\exceptions\IdNotFoundException($seminaryId);
}
return $seminary[0];
}
/**
* Get a seminary and its data by its URL-title.
*
* @throws IdNotFoundException
* @param string $seminaryUrl URL-Title of a seminary
* @return array Seminary
*/
public function getSeminaryByUrl($seminaryUrl)
{
$seminary = $this->db->query(
'SELECT id, created, created_user_id, title, url '.
'FROM seminaries '.
'WHERE url = ?',
's',
$seminaryUrl
);
if(empty($seminary)) {
throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
}
return $seminary[0];
}
}
?>

105
models/UsersModel.inc Normal file
View file

@ -0,0 +1,105 @@
<?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 UsersAgent to list users and get their data.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class UsersModel extends \hhu\z\Model
{
/**
* Construct a new UsersModel.
*/
public function __construct()
{
parent::__construct();
}
/**
* Get registered users.
*
* @return array Users
*/
public function getUsers()
{
return $this->db->query(
'SELECT id, created, username, url, surname, prename, email '.
'FROM users '.
'ORDER BY username ASC'
);
}
/**
* Get a user and its data by its ID.
*
* @throws IdNotFoundException
* @param int $userId ID of an user
* @return array Userdata
*/
public function getUserById($userId)
{
// Get user
$user = $this->db->query(
'SELECT id, created, username, url, surname, prename, email '.
'FROM users '.
'WHERE id = ?',
'i',
$userId
);
if(empty($user)) {
throw new \nre\exceptions\IdNotFoundException($userId);
}
return $user[0];
}
/**
* Get a user and its data by its URL-username.
*
* @throws IdNotFoundException
* @param string $userUrl URL-Username of an user
* @return array Userdata
*/
public function getUserByUrl($userUrl)
{
// Get user
$user = $this->db->query(
'SELECT id, created, username, url, surname, prename, email '.
'FROM users '.
'WHERE url = ?',
's',
$userUrl
);
if(empty($user)) {
throw new \nre\exceptions\IdNotFoundException($userUrl);
}
return $user[0];
}
}
?>

View file

@ -11,9 +11,12 @@
<body>
<header>
<h1>The Legend of Z</h1>
<?=$menu?>
<nav>
<?=$menu?>
</nav>
</header>
<article>
<h1><?=$title?></h1>
<?=$intermediate?>
</article>
</body>

View file

@ -1,2 +1,4 @@
<nav>
</nav>
<menu>
<li><a href="<?=$linker->link("users")?>">Users</a></li>
<li><a href="<?=$linker->link("seminaries")?>">Seminaries</a></li>
</menu>

View file

@ -0,0 +1,10 @@
<ul>
<?php foreach($seminaries as &$seminary) : ?>
<li>
<h2><a href="<?=$linker->link(array('seminary', $seminary['url']), 1)?>"><?=$seminary['title']?></a></h2>
<details>
<summary>erstellt von <?=$seminary['creator']['username']?></summary>
</details>
</li>
<?php endforeach ?>
</ul>

View file

@ -0,0 +1,4 @@
<h2><?=$seminary['title']?></h2>
<p>
erstellt am <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($seminary['created']))?>
</p>

View file

@ -0,0 +1,10 @@
<ul>
<?php foreach($users as &$user) : ?>
<li>
<h2><a href="<?=$linker->link(array('user', $user['username']), 1)?>"><?=$user['username']?></a></h2>
<details>
<summary>registriert seit <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($user['created']))?></summary>
</details>
</li>
<?php endforeach ?>
</ul>

View file

@ -0,0 +1,4 @@
<h2><?=$user['username']?></h2>
<p>
registriert seit <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($user['created']))?>
</p>