Skip to content

Instantly share code, notes, and snippets.

@jbennett
Created May 7, 2011 12:02
Show Gist options
  • Save jbennett/960447 to your computer and use it in GitHub Desktop.
Save jbennett/960447 to your computer and use it in GitHub Desktop.
Relevant URLS:
Full JSON dataset: option=com_gives&view=opportunities&format=json
Reduced JSON dataset: option=com_gives&view=opportunities&format=json&detail=short
<?php
class ComGivesViewOpportunitiesJson extends KViewJson
{
public function display()
{
if(empty($this->output)) {
$model = $this->getModel();
$items = $model->getList()->toArray();
$data = array();
foreach ($items as $index=>$row) {
$data[$index] = array_filter($row);
}
$this->output = json_encode($data);
}
return parent::display();
}
}
<?php
class ComGivesModelOpportunities extends ComDefaultModelDefault
{
public function __construct(KConfig $config)
{
parent::__construct($config);
$this->_state
->insert('detail', 'cmd')
}
protected function _buildQueryColumns(KDatabaseQuery $query)
{
if (isset($this->_state->detail)) {
if ($this->_state->detail === 'short') {
$query->select(array(
'tbl.gives_opportunity_id',
'tbl.title',
));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment