Skip to content

Commit

Permalink
Use a factory for the Trean_TagBrowser.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Apr 3, 2014
1 parent ff6eb3b commit 8ddf828
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 14 deletions.
2 changes: 2 additions & 0 deletions trean/lib/Application.php
Expand Up @@ -54,6 +54,8 @@ protected function _init()
throw new Horde_Exception('The Content_Tagger class could not be found. Make sure the Content application is installed.');
}

$GLOBALS['injector']->bindFactory('Trean_TagBrowser', 'Trean_Factory_TagBrowser', 'create');

// Set the timezone variable.
$GLOBALS['registry']->setTimeZone();

Expand Down
50 changes: 50 additions & 0 deletions trean/lib/Factory/TagBrowser.php
@@ -0,0 +1,50 @@
<?php
/**
* The factory for the calendars handler.
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Gunnar Wrobel <wrobel@pardus.de>
* @package Kronolith
*/
class Trean_Factory_TagBrowser
{
/*
* The injector.
*
* @var Horde_Injector
*/
protected $_injector;

/**
* The tag browser
*
* @var Trean_TagBrowser
*/
protected $_browser;

/**
* Constructor.
*
* @param Horde_Injector $injector The injector to use.
*/
public function __construct(Horde_Injector $injector)
{
$this->_injector = $injector;
}

/**
* Return a Trean_TagBrowser
*
* @return Trean_TagBrowser
*/
public function create()
{
if (empty($_browser)) {
$this->_browser = new Trean_TagBrowser($this->_injector->getInstance('Trean_Tagger'));
}

return $this->_browser;
}
}
13 changes: 13 additions & 0 deletions trean/lib/TagBrowser.php
Expand Up @@ -54,4 +54,17 @@ public function getSlice($page = 0, $perpage = null)

return $bookmarks;
}

/**
* Return a URL to add a new tag to the current search.
*
* @param string $tag The tag we want to add.
*
* @return string
*/
public function addTagLink($tag)
{
return Horde::url('browse.php')->add(array('tag' => $tag));
}

}
16 changes: 2 additions & 14 deletions trean/lib/View/BookmarkList.php
Expand Up @@ -63,8 +63,7 @@ public function __construct($bookmarks = null, $browser = null)
if ($browser) {
$this->_browser = $browser;
} else {
$this->_browser = new Trean_TagBrowser(
$GLOBALS['injector']->getInstance('Trean_Tagger'));
$this->_browser = $GLOBALS['injector']->getInstance('Trean_TagBrowser');
}

$action = Horde_Util::getFormData('actionID', '');
Expand Down Expand Up @@ -190,7 +189,7 @@ protected function _getRelatedTags()
. Horde::img('tags.png') . ' <ul class="horde-tags">';
foreach ($rtags as $id => $taginfo) {
$html .= '<li>'
. $this->_linkAddTag($taginfo['tag_name'])->link()
. $GLOBALS['injector']->getInstance('Trean_TagBrowser')->addTagLink($taginfo['tag_name'])->link()
. htmlspecialchars($taginfo['tag_name']) . '</a></li>';
}
return $html . '</ul></div>';
Expand Down Expand Up @@ -233,15 +232,4 @@ protected function _linkRemoveTag($tag)
->add(array('actionID' => 'remove', 'tag' => $tag));
}

/**
* Get HTML for a link to add a new tag to the current search.
*
* @param string $tag The tag we want to add.
*
* @return string
*/
protected function _linkAddTag($tag)
{
return Horde::url('browse.php')->add(array('tag' => $tag));
}
}

0 comments on commit 8ddf828

Please sign in to comment.