Skip to content

Instantly share code, notes, and snippets.

@rjmackay
Created August 8, 2012 02:14
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 rjmackay/3291463 to your computer and use it in GitHub Desktop.
Save rjmackay/3291463 to your computer and use it in GitHub Desktop.
Ushahidi Category Blocks
<?php blocks::open("reports");?>
<?php blocks::title(Kohana::lang('ui_main.reports_listed'));?>
<table class="table-list">
<thead>
<tr>
<th scope="col" class="title"><?php echo Kohana::lang('ui_main.title'); ?></th>
<th scope="col" class="location"><?php echo Kohana::lang('ui_main.location'); ?></th>
<th scope="col" class="date"><?php echo Kohana::lang('ui_main.date'); ?></th>
</tr>
</thead>
<tbody>
<?php
if ($incidents->count() == 0)
{
?>
<tr><td colspan="3"><?php echo Kohana::lang('ui_main.no_reports'); ?></td></tr>
<?php
}
foreach ($incidents as $incident)
{
$incident_id = $incident->id;
$incident_title = text::limit_chars(strip_tags($incident->incident_title), 40, '...', True);
$incident_date = $incident->incident_date;
$incident_date = date('M j Y', strtotime($incident->incident_date));
$incident_location = $incident->location->location_name;
?>
<tr>
<td><a href="<?php echo url::site() . 'reports/view/' . $incident_id; ?>"> <?php echo html::specialchars($incident_title) ?></a></td>
<td><?php echo html::specialchars($incident_location) ?></td>
<td><?php echo $incident_date; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<a class="more" href="<?php echo url::site() . 'reports/' ?>"><?php echo Kohana::lang('ui_main.view_more'); ?></a>
<div style="clear:both;"></div>
<?php blocks::close();?>
<?php defined('SYSPATH') or die('No direct script access.');
// Start wildlife category block
class category_wildlife_block { // CHANGE THIS FOR OTHER BLOCKS
public function __construct()
{
// Array of block params
$block = array(
"classname" => "category_wildlife_block", // Must match class name aboce
"name" => "Wildlife Reports",
"description" => "List the 10 latest reports in the wildlife category"
);
// register block with core, this makes it available to users
blocks::register($block);
}
public function block()
{
// Load the reports block view
$content = new View('blocks/category_wildlife_block'); // CHANGE THIS IF YOU WANT A DIFFERENT VIEW
// ID of the category we're looking for
$category_id = 7; // CHANGE THIS
// Get Reports
$content->incidents = ORM::factory('incident')
->with('location')
->join('incident_category', 'incident.id', 'incident_category.incident_id')
->where('incident_active', '1')
->where('category_id', $category_id)
->limit('10')
->orderby('incident_date', 'desc')
->find_all();
echo $content;
}
}
new category_wildlife_block;
@rjmackay
Copy link
Author

rjmackay commented Aug 8, 2012

register_category_blocks.php goes in themes/MYTHEME/hooks/

category_wildlife_block.php goes in themes/MYTHEME/views/blocks/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment