Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add events tierra.topicsolved.mark_solved|unsolved_after #43

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ tierra_topicsolved_controller_mark:
defaults: { _controller: tierra.topicsolved.controller:mark }
requirements:
solve: solved|unsolved
post_id: \d+
post_id: \d+
3 changes: 2 additions & 1 deletion config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ services:
- @dbal.conn
- @user
- @auth
- @dispatcher
- %core.root_path%
- %core.php_ext%
- %core.php_ext%
2 changes: 1 addition & 1 deletion tests/controller/main_controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function get_controller($user_id, $mode)

$auth = $this->getMock('\phpbb\auth\auth');

$this->topicsolved = new topicsolved($this->new_dbal(), $user, $auth, $phpbb_root_path, $phpEx);
$this->topicsolved = new topicsolved($this->new_dbal(), $user, $auth, $phpbb_dispatcher, $phpbb_root_path, $phpEx);

return new main_controller($this->topicsolved);
}
Expand Down
6 changes: 5 additions & 1 deletion tests/topicsolved_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class topicsolved_test extends \phpbb_database_test_case
/** @var \phpbb\auth\auth|\PHPUnit_Framework_MockObject_MockObject */
protected $auth;

/** @var \phpbb\event\dispatcher|\PHPUnit_Framework_MockObject_MockObject */
protected $dispatcher;

/**
* Configure the test environment.
*
Expand All @@ -40,9 +43,10 @@ public function setUp()

$this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
$this->auth = $this->getMock('\phpbb\auth\auth');
$this->dispatcher = new \phpbb_mock_event_dispatcher();

$this->topicsolved = new topicsolved(
$this->new_dbal(), $this->user, $this->auth, $phpbb_root_path, $phpEx
$this->new_dbal(), $this->user, $this->auth, $this->dispatcher, $phpbb_root_path, $phpEx
);
}

Expand Down
34 changes: 34 additions & 0 deletions topicsolved.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class topicsolved
/** @var \phpbb\auth\auth */
protected $auth;

/** @var \phpbb\event\dispatcher_interface */
protected $dispatcher;

/** @var string core.root_path */
protected $root_path;

Expand All @@ -47,18 +50,21 @@ class topicsolved
* @param \phpbb\db\driver\driver_interface $db Database object
* @param \phpbb\user $user
* @param \phpbb\auth\auth $auth
* @param \phpbb\event\dispatcher_interface $dispatcher
* @param string $root_path core.root_path
* @param string $php_ext core.php_ext
*/
public function __construct(
\phpbb\db\driver\driver_interface $db,
\phpbb\user $user,
\phpbb\auth\auth $auth,
\phpbb\event\dispatcher_interface $dispatcher,
$root_path, $php_ext)
{
$this->db = $db;
$this->user = $user;
$this->auth = $auth;
$this->dispatcher = $dispatcher;
$this->root_path = $root_path;
$this->php_ext = $php_ext;

Expand Down Expand Up @@ -180,6 +186,20 @@ public function mark_solved($topic_data, $post_id)
}

$this->update_topic($topic_data['topic_id'], $column_data);

/**
* This event allows you to perform additional actions after a topic has been marked as solved.
*
* @event tierra.topicsolved.mark_solved_after
* @var array topic_data Array with general topic data
* @var array column_data Array with topic data that the database has been updated with
* @since 2.2.0
*/
$vars = array(
'topic_data',
'column_data',
);
extract($this->dispatcher->trigger_event('tierra.topicsolved.mark_solved_after', compact($vars)));
}

/**
Expand All @@ -199,6 +219,20 @@ public function mark_unsolved($topic_data)
}

$this->update_topic($topic_data['topic_id'], $column_data);

/**
* This event allows you to perform additional actions after a topic has been marked as unsolved.
*
* @event tierra.topicsolved.mark_unsolved_after
* @var array topic_data Array with general topic data
* @var array column_data Array with topic data that the database has been updated with
* @since 2.2.0
*/
$vars = array(
'topic_data',
'column_data',
);
extract($this->dispatcher->trigger_event('tierra.topicsolved.mark_unsolved_after', compact($vars)));
}

/**
Expand Down