Skip to content

Commit

Permalink
Move the titania_tags class to the DIC.
Browse files Browse the repository at this point in the history
  • Loading branch information
prototech committed Jul 11, 2015
1 parent fe9efb7 commit ddd19e5
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 80 deletions.
1 change: 1 addition & 0 deletions config/controllers.yml
Expand Up @@ -232,6 +232,7 @@ services:
- @request
- @phpbb.titania.config
- @phpbb.titania.display
- @phpbb.titania.tags

phpbb.titania.controller.manage.queue.tools:
class: phpbb\titania\controller\manage\queue\tools
Expand Down
6 changes: 6 additions & 0 deletions config/services.yml
Expand Up @@ -76,3 +76,9 @@ services:
- @user
- @template


phpbb.titania.tags:
class: phpbb\titania\tags
arguments:
- @user
- @phpbb.titania.cache
31 changes: 28 additions & 3 deletions controller/manage/queue/item.php
Expand Up @@ -15,6 +15,9 @@

class item extends \phpbb\titania\controller\manage\base
{
/** @var \phpbb\titania\tags */
protected $tags;

/** @var int */
protected $id;

Expand All @@ -30,6 +33,28 @@ class item extends \phpbb\titania\controller\manage\base
/** @var bool */
protected $is_author;

/**
* Constructor
*
* @param \phpbb\auth\auth $auth
* @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\template\template $template
* @param \phpbb\user $user
* @param \phpbb\titania\cache\service $cache
* @param \phpbb\titania\controller\helper $helper
* @param \phpbb\request\request $request
* @param \phpbb\titania\config\config $ext_config
* @param \phpbb\titania\display $display
* @param \phpbb\titania\tags $tags
*/
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\titania\cache\service $cache, \phpbb\titania\controller\helper $helper, \phpbb\request\request $request, \phpbb\titania\config\config $ext_config, \phpbb\titania\display $display, \phpbb\titania\tags $tags)
{
parent::__construct($auth, $config, $db, $template, $user, $cache, $helper, $request, $ext_config, $display);

$this->tags = $tags;
}

/**
* Display queue item.
*
Expand Down Expand Up @@ -61,8 +86,8 @@ public function display_item($id)
{
// Add tag to Breadcrumbs
$this->display->generate_breadcrumbs(array(
\titania_tags::get_tag_name($tag) => $this->queue->get_url(false, array('tag' => $tag)),
));
$this->tags->get_tag_name($tag) => $this->queue->get_url(false, array('tag' => $tag)),
));
}

return $this->helper->render('manage/queue.html', \queue_overlord::$queue[$this->id]['topic_subject']);
Expand Down Expand Up @@ -325,7 +350,7 @@ protected function move()
return $this->helper->error('NO_TAG');
}

$this->queue->move($new_tag);
$this->queue->move($new_tag, $this->tags);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions includes/objects/queue.php
Expand Up @@ -315,12 +315,12 @@ public function delete()
parent::delete();
}

public function move($new_status)
public function move($new_status, \phpbb\titania\tags $tags)
{
$this->user->add_lang_ext('phpbb/titania', 'manage');

$from = titania_tags::get_tag_name($this->queue_status);
$to = titania_tags::get_tag_name($new_status);
$from = $tags->get_tag_name($this->queue_status);
$to = $tags->get_tag_name($new_status);

$this->topic_reply(sprintf(phpbb::$user->lang['QUEUE_REPLY_MOVE'], $from, $to));

Expand Down
74 changes: 0 additions & 74 deletions includes/tools/tags.php

This file was deleted.

94 changes: 94 additions & 0 deletions tags.php
@@ -0,0 +1,94 @@
<?php
/**
*
* This file is part of the phpBB Customisation Database package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

namespace phpbb\titania;

class tags
{
/** @var \phpbb\user */
protected $user;

/** @var \phpbb\titania\cache\service */
protected $cache;

/** @var array */
protected $tags = array();

/**
* Constructor
*
* @param \phpbb\user $user
* @param \phpbb\titania\cache\service $cache
*/
public function __construct(\phpbb\user $user, \phpbb\titania\cache\service $cache)
{
$this->user = $user;
$this->cache = $cache;
}

/**
* Load tags
*/
protected function load_tags()
{
if (!empty($this->tags))
{
return;
}

foreach ($this->cache->get_tags() as $children)
{
foreach ($children as $id => $row)
{
$this->tags[$id] = $row;
}
}
}

/**
* Get a tag row from what was loaded
*
* @param mixed $tag_id
* @return array
*/
public function get_tag($tag_id)
{
$this->load_tags();

if (!isset($this->tags[$tag_id]))
{
return false;
}

return $this->tags[$tag_id];
}

/**
* Get the tag name
*
* @param mixed $tag_id
* @return string
*/
public function get_tag_name($tag_id)
{
$lang = $this->user->lang('UNKNOWN');

$row = $this->get_tag($tag_id);
if ($row)
{
$lang = $this->user->lang($row['tag_field_name']);
}

return $lang;
}
}

0 comments on commit ddd19e5

Please sign in to comment.