implement MediaAgent for displaying media
This commit is contained in:
parent
0d474e2fba
commit
e11b07ead6
5 changed files with 198 additions and 0 deletions
35
agents/intermediate/MediaAgent.inc
Normal file
35
agents/intermediate/MediaAgent.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 process and show media.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MediaAgent extends \nre\agents\IntermediateAgent
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*/
|
||||
public function index(\nre\core\Request $request, \nre\core\Response $response)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
72
controllers/MediaController.inc
Normal file
72
controllers/MediaController.inc
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?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 MediaAgent to process and show Media.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MediaController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* 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')
|
||||
);
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* TODO Action: index.
|
||||
*/
|
||||
public function index($seminaryUrl, $mediaUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Media
|
||||
$media = $this->Media->getMediaByUrl($seminary['id'], $mediaUrl);
|
||||
|
||||
// Set content-type
|
||||
$this->response->addHeader("Content-type: ".$media['mimetype']."");
|
||||
|
||||
// Set filename
|
||||
$media['filename'] = ROOT.DS.'media'.DS.$media['id'];
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('media', $media);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
0
media/empty
Normal file
0
media/empty
Normal file
90
models/MediaModel.inc
Normal file
90
models/MediaModel.inc
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?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 the Media-tables.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MediaModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new MediaModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a Medium by its URL.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the seminary
|
||||
* @param string $mediaURL URL-name of the Medium
|
||||
* @return array Medium data
|
||||
*/
|
||||
public function getMediaByUrl($seminaryId, $mediaUrl)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url, description, mimetype '.
|
||||
'FROM media '.
|
||||
'WHERE media.url = ?',
|
||||
's',
|
||||
$mediaUrl
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($mediaUrl);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Medium by its ID.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param int $seminaryId ID of the seminary
|
||||
* @param int $mediaId ID of the Medium
|
||||
* @return array Medium data
|
||||
*/
|
||||
public function getMediaById($mediaId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, name, url, description, mimetype '.
|
||||
'FROM media '.
|
||||
'WHERE media.id = ?',
|
||||
'i',
|
||||
$mediaId
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($mediaId);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
1
views/binary/media/index.tpl
Normal file
1
views/binary/media/index.tpl
Normal file
|
|
@ -0,0 +1 @@
|
|||
<?=file_get_contents($media['filename'])?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue