Skip to content

Instantly share code, notes, and snippets.

@mbabker
Created February 13, 2014 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbabker/8978557 to your computer and use it in GitHub Desktop.
Save mbabker/8978557 to your computer and use it in GitHub Desktop.
IssueJsonView.php
<?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