Created
February 13, 2014 16:33
-
-
Save mbabker/8978557 to your computer and use it in GitHub Desktop.
IssueJsonView.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Part of the Joomla Tracker's Tracker Application | |
* | |
* @copyright Copyright (C) 2012 - 2014 Open Source Matters, Inc. All rights reserved. | |
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later | |
*/ | |
namespace App\Tracker\View\Issue; | |
use App\Projects\TrackerProject; | |
use App\Tracker\Model\IssueModel; | |
use Joomla\View\AbstractView; | |
/** | |
* The issues item view | |
* | |
* @since 1.0 | |
*/ | |
class IssueJsonView extends AbstractView | |
{ | |
/** | |
* Redefine the model so the correct type hinting is available. | |
* | |
* @var IssueModel | |
* @since 1.0 | |
*/ | |
protected $model; | |
/** | |
* Item ID | |
* | |
* @var integer | |
* @since 1.0 | |
*/ | |
private $id = 0; | |
/** | |
* Project object | |
* | |
* @var TrackerProject | |
* @since 1.0 | |
*/ | |
protected $project = null; | |
/** | |
* Method to render the view. | |
* | |
* @return string The rendered view. | |
* | |
* @since 1.0 | |
* @throws \RuntimeException | |
*/ | |
public function render() | |
{ | |
$item = $this->model->getItem($this->getId()); | |
return json_encode(array('item' => $item, 'project' => $this->getProject(), 'statuses', $this->model->getStatuses())); | |
} | |
/** | |
* Get the id. | |
* | |
* @return integer | |
* | |
* @since 1.0 | |
*/ | |
public function getId() | |
{ | |
if (0 == $this->id) | |
{ | |
// New record. | |
} | |
return $this->id; | |
} | |
/** | |
* Set the project. | |
* | |
* @param integer $id The id | |
* | |
* @return $this Method allows chaining | |
* | |
* @since 1.0 | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
return $this; | |
} | |
/** | |
* Get the project. | |
* | |
* @return TrackerProject | |
* | |
* @since 1.0 | |
* @throws \RuntimeException | |
*/ | |
public function getProject() | |
{ | |
if (is_null($this->project)) | |
{ | |
throw new \RuntimeException('No project set.'); | |
} | |
return $this->project; | |
} | |
/** | |
* Set the project. | |
* | |
* @param TrackerProject $project The project. | |
* | |
* @return $this Method allows chaining | |
* | |
* @since 1.0 | |
*/ | |
public function setProject(TrackerProject $project) | |
{ | |
$this->project = $project; | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment