From 57a1cb0527b56735e3b09efb57ee19a79ba25281 Mon Sep 17 00:00:00 2001 From: coderkun Date: Fri, 14 Feb 2014 18:56:12 +0100 Subject: [PATCH] implement MediaAgent for displaying media --- agents/intermediate/MediaAgent.inc | 35 ++++++++++++ controllers/MediaController.inc | 72 ++++++++++++++++++++++++ media/empty | 0 models/MediaModel.inc | 90 ++++++++++++++++++++++++++++++ views/binary/media/index.tpl | 1 + 5 files changed, 198 insertions(+) create mode 100644 agents/intermediate/MediaAgent.inc create mode 100644 controllers/MediaController.inc create mode 100644 media/empty create mode 100644 models/MediaModel.inc create mode 100644 views/binary/media/index.tpl diff --git a/agents/intermediate/MediaAgent.inc b/agents/intermediate/MediaAgent.inc new file mode 100644 index 00000000..c3fd35ae --- /dev/null +++ b/agents/intermediate/MediaAgent.inc @@ -0,0 +1,35 @@ + + * @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 + */ + class MediaAgent extends \nre\agents\IntermediateAgent + { + + + + + /** + * Action: index. + */ + public function index(\nre\core\Request $request, \nre\core\Response $response) + { + } + + } + +?> diff --git a/controllers/MediaController.inc b/controllers/MediaController.inc new file mode 100644 index 00000000..60ad460d --- /dev/null +++ b/controllers/MediaController.inc @@ -0,0 +1,72 @@ + + * @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 + */ + 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); + } + + } + +?> diff --git a/media/empty b/media/empty new file mode 100644 index 00000000..e69de29b diff --git a/models/MediaModel.inc b/models/MediaModel.inc new file mode 100644 index 00000000..6165f7df --- /dev/null +++ b/models/MediaModel.inc @@ -0,0 +1,90 @@ + + * @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 + */ + 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]; + } + + } + +?> diff --git a/views/binary/media/index.tpl b/views/binary/media/index.tpl new file mode 100644 index 00000000..d0f3e0cd --- /dev/null +++ b/views/binary/media/index.tpl @@ -0,0 +1 @@ +