Skip to content

Commit

Permalink
Tag displaying and cloud etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson committed Oct 27, 2012
1 parent ec176f4 commit ef12b68
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 175 deletions.
10 changes: 7 additions & 3 deletions application/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@
'format'=>'(html|pdf)',
))->defaults(array(
'controller'=>'index',
'action'=>'index',
'action'=>'dates',
'format'=>'html',
));
Route::set('tags', 'tags(/<tag>)')->defaults(array(
Route::set('tags', 'tags(/<tag_ids>(.<format>))', array(
'tag_ids'=>'[-+0-9]*',
'format'=>'(html|pdf)',
))->defaults(array(
'controller'=>'index',
'action'=>'tag',
'action'=>'tags',
'format'=>'html',
));
Route::set('view', '<id>(.<format>)', array(
'id' => '[0-9]+',
Expand Down
113 changes: 73 additions & 40 deletions application/classes/controller/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function before()
//$this->template->bind_global('current_month_number', $false);
}

public function action_index()
public function action_dates()
{
$this->template->selected_toplink = Route::url('dates');

Expand Down Expand Up @@ -114,54 +114,87 @@ public function action_index()
}
}

public function action_tag()
public function action_tags()
{
$this->view = View::factory('blog/index');
$this->template->selected_toplink = Route::url('tags');
$this->view = View::factory('tags');
$this->template->content = $this->view;

$sql = "SELECT DATE_FORMAT(date_and_time, '%Y') AS year FROM images
UNION SELECT DATE_FORMAT(date_and_time, '%Y') AS year FROM journal_entries
GROUP BY YEAR(date_and_time) ORDER BY year DESC";
$this->view->years = Database::instance()->query(Database::SELECT, $sql, TRUE);

$tag = urldecode($this->request->param('tag', FALSE));
// Get the tag IDs
$this->view->current_tags = $this->request->param('tag_ids', '');
$tags = Model_Tags::parse($this->view->current_tags);
$included_tags = array();
$excluded_tags = array();
foreach ($tags as $tag=>$sign) {
if ($sign == '-') {
$excluded_tags[] = $tag;
} else {
$included_tags[] = $tag;
}
}

$imgs = ORM::factory('images')
->or_where_open()
->where('auth_level_id', '<=', $this->user->auth_level)
->or_where('auth_level_id', '=', 1)
->or_where_close()
->join('image_tags')->on('image_id', '=', 'images.id')
->join('tags')->on('tag_id', '=', 'tags.id')
->where('name', 'LIKE', $tag)
->find_all();
$images = array();
$item_id = 1;
foreach ($imgs as $img)
// Get all photos.
$photos = ORM::factory('images')
->or_where_open()
->where('auth_level_id', '<=', $this->user->auth_level)
->or_where('auth_level_id', '=', 1)
->or_where_close()
->group_by('images.id');
if (count($included_tags) > 0)
{
$images[$img->date_and_time.$item_id.'i'] = $img;
$item_id++;
foreach ($included_tags as $included_tag) {
$alias = uniqid('it_');
$photos->join(array('image_tags', $alias))
->on($alias.'.image_id', '=', 'images.id')
->on($alias.'.tag_id', '=', DB::expr($included_tag));
}
}
$jes = ORM::factory('JournalEntries')
->or_where_open()
->where('auth_level_id', '<=', $this->user->auth_level)
->or_where('auth_level_id', '=', 1)
->or_where_close()
->join('journal_entry_tags')->on('journal_entry_id', '=', 'journalentries.id')
->join('tags')->on('tag_id', '=', 'tags.id')
->where('tags.name', 'LIKE', $tag)
->find_all();
$journal_entries = array();
foreach ($jes as $je)
if (count($excluded_tags) > 0)
{
$journal_entries[$je->date_and_time.$item_id.'je'] = $je;
$item_id++;
$exclude = DB::select()
->from('image_tags')
->where('image_id', '=', DB::expr('images.id'))
->where('tag_id', 'IN', $excluded_tags);
$photos->where(DB::expr('NOT EXISTS'), '', $exclude);
}
$this->view->items = array_merge($images, $journal_entries);
ksort($this->view->items);
$this->view->photos = $photos->order_by('date_and_time')->find_all();

$this->title = 'All items tagged &lsquo;'.$tag.'&rsquo;';
$this->template->tag = $tag;
// Get all tags.
$all_tags = ORM::factory('Tags')
->select(array('tags.id', 'id'))
->select(array('tags.name', 'name'))
->select(array(DB::expr('COUNT(DISTINCT it2.image_id)'), 'count'))
->join('image_tags')->on('tags.id', '=', 'image_tags.tag_id')
->join(array('images','i1'))->on('image_tags.image_id', '=', 'i1.id')
->join(array('image_tags','it2'))->on('i1.id', '=', 'it2.image_id')
->join(array('images','i2'))->on('image_tags.image_id', '=', 'i2.id')
->and_where_open()
->where('i1.auth_level_id', '<=', $this->user->auth_level)
->or_where('i1.auth_level_id', '=', 1)
->and_where_close()
->and_where_open()
->where('i2.auth_level_id', '<=', $this->user->auth_level)
->or_where('i2.auth_level_id', '=', 1)
->and_where_close()
->order_by('tags.name')
->group_by('tags.id'); // ->group_by('it2.image_id');
if (count($included_tags) > 0)
{
foreach ($included_tags as $included_tag) {
$alias = uniqid('it_');
$photos->join(array('image_tags', $alias))
->on($alias.'.image_id', '=', 'images.id')
->on($alias.'.tag_id', '=', DB::expr($included_tag));
}
//$all_tags->where('it2.tag_id', 'IN', $included_tags);
}
if (count($excluded_tags) > 0)
{
$all_tags->where('it2.tag_id', 'NOT IN', $excluded_tags);
}
$this->view->tags = $all_tags->find_all();

$this->title = 'Tagged Photos';
}

/**
Expand Down
29 changes: 29 additions & 0 deletions application/classes/model/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class Model_Tags extends ORM {

protected $_table_name = 'tags';

protected static $_currently_selected;

protected $_has_many = array(
'images'=>array('model'=>'images', 'through'=>'tags_to_images', 'far_key'=>'image', 'foreign_key'=>'tag'),
Expand All @@ -23,4 +25,31 @@ public function get_list($quoted)
return implode($glue, $out);
}

static public function parse($string, $remove = FALSE)
{
preg_match_all('/([-+][0-9]+)/', $string, $matches);
//echo Kohana_Debug::vars($matches);
$tags = array();
foreach ($matches[0] as $tag)
{
$id = substr($tag, 1);
if ($id != $remove)
{
$tags["$id"] = substr($tag,0,1);
}
}
ksort($tags);
return $tags;
}

public function url($existing, $remove = FALSE)
{
$result = '';
foreach ($this->parse($existing, $remove) as $tag=>$sign)
{
$result .= $sign.$tag;
}
return URL::site("tags/$result");
}

}
60 changes: 60 additions & 0 deletions application/views/dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

<div class="menu">
<ol>
<?php foreach ($years as $year): ?>

<?php
$year_title = ($year->year=='0000') ? 'Year Unknown' : $year->year;
if (isset($current_year) && $year->year==$current_year): ?>
<li class="year selected">
<a class="year"><?php echo $year_title; ?></a>
<ol class="months">
<?php foreach ($months as $month): ?>

<?php
if ($month->month=='00')
{
$month_name = 'unknown';
$month_title = 'Month Unknown';
} else
{
$month_title = date('F', strtotime("2010-$month->month-01"));
$month_name = $month_title;
}
?>

<?php if ($month->month==$current_month): ?>
<li class="month selected">
<a><?php echo $month_title ?></a>
</li>

<?php else: ?>
<li class="month">
<a href="<?php echo Route::url('dates', array('year'=>$current_year, 'month'=>$month->month)) ?>">
<?php echo $month_title ?>
</a>
</li>
<?php endif ?>

<?php endforeach ?>
</ol>
</li>
<?php else: ?>
<li>
<a href="<?php echo Route::url('dates', array('year'=>$year->year, 'month'=>$current_month)) ?>">
<?php echo $year_title ?>
</a>
</li>
<?php endif ?>

<?php endforeach ?>
</ol>
</div>



<?php echo View::factory('thumbs')
->bind('photos', $photos)
->bind('title', $title)
->render() ?>

File renamed without changes.
21 changes: 0 additions & 21 deletions application/views/images/index.php

This file was deleted.

97 changes: 0 additions & 97 deletions application/views/index.php

This file was deleted.

File renamed without changes.
Loading

0 comments on commit ef12b68

Please sign in to comment.