Created
August 8, 2012 02:14
-
-
Save rjmackay/3291463 to your computer and use it in GitHub Desktop.
Ushahidi Category Blocks
This file contains hidden or 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 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();?> |
This file contains hidden or 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 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
register_category_blocks.php goes in themes/MYTHEME/hooks/
category_wildlife_block.php goes in themes/MYTHEME/views/blocks/