Skip to content

Commit

Permalink
Adding new on_board_index rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gouarfig committed Jan 24, 2019
1 parent d8c9a7d commit 7081e39
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 41 deletions.
17 changes: 1 addition & 16 deletions acp/board_notices_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,6 @@ public function displayNoticeForm($action, $data, $error = '')
// Output data to the template
$this->template->assign_vars(array(
'S_BOARD_NOTICES' => true,
'LABEL_BOARD_NOTICE_ACTIVE' => $this->user->lang('LABEL_BOARD_NOTICE_ACTIVE'),
'LABEL_BOARD_NOTICE_TITLE' => $this->user->lang('LABEL_BOARD_NOTICE_TITLE'),
'LABEL_BOARD_NOTICE_PREVIEW' => $this->user->lang('LABEL_BOARD_NOTICE_PREVIEW'),
'LABEL_BOARD_NOTICE_TEXT' => $this->user->lang('LABEL_BOARD_NOTICE_TEXT'),
'LABEL_BOARD_NOTICE_BGCOLOR' => $this->user->lang('LABEL_BOARD_NOTICE_BGCOLOR'),
'LABEL_BOARD_NOTICE_BGCOLOR_EXPLAIN' => $this->user->lang('LABEL_BOARD_NOTICE_BGCOLOR_EXPLAIN'),
'LABEL_BOARD_NOTICE_STYLE' => $this->user->lang('LABEL_BOARD_NOTICE_STYLE'),
'LABEL_BOARD_NOTICE_STYLE_EXPLAIN' => $this->user->lang('LABEL_BOARD_NOTICE_STYLE_EXPLAIN'),
'ERRORS' => $error,
'NOTICE_ID' => isset($data['notice_id']) ? $data['notice_id'] : '',
'BOARD_NOTICE_ACTIVE' => $data['active'],
Expand All @@ -328,18 +320,11 @@ public function displayNoticeForm($action, $data, $error = '')
'S_BBCODE_DISABLE_CHECKED' => !$notice_text_edit['allow_bbcode'],
'S_SMILIES_DISABLE_CHECKED' => !$notice_text_edit['allow_smilies'],
'S_MAGIC_URL_DISABLE_CHECKED' => !$notice_text_edit['allow_urls'],
'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '', ''),
'SMILIES_STATUS' => $this->user->lang('SMILIES_ARE_ON'),
'IMG_STATUS' => $this->user->lang('IMAGES_ARE_ON'),
'FLASH_STATUS' => $this->user->lang('FLASH_IS_ON'),
'URL_STATUS' => $this->user->lang('URL_IS_ON'),
'S_BBCODE_ALLOWED' => true,
'S_SMILIES_ALLOWED' => true,
'S_LINKS_ALLOWED' => true,
'S_BBCODE_IMG' => true,
'S_BBCODE_FLASH' => true,
'L_INFO' => $this->user->lang('L_INFORMATION'),
'VARIABLES_EXPLAIN' => $this->user->lang('VARIABLES_EXPLAIN'),
'U_BACK' => $this->u_action,
'U_ACTION' => $this->u_action . '&action=' . $action,
'ALLRULES_COLSPAN' => 4,
Expand Down Expand Up @@ -538,7 +523,7 @@ private function getDisplayYesNoConditions($input_name, $selected)
{
$display = '';
$display .= '<label><input type="radio" class="radio" id="' . $input_name . '" name="' . $input_name . '[0]" value="1"' . ($selected ? ' checked="checked"' : '') . ' /> ' . $this->user->lang['YES'] . '</label>';
$display .= '<label><input type="radio" class="radio" name="' . $input_name . '[0]" value="0"' . (!$selected ? ' checked="checked"' : '') . ' /> ' . $this->user->lang['NO_GUEST_OR_BOT'] . '</label>';
$display .= '<label><input type="radio" class="radio" name="' . $input_name . '[0]" value="0"' . (!$selected ? ' checked="checked"' : '') . ' /> ' . $this->user->lang['NO'] . '</label>';
return $display;
}

Expand Down
22 changes: 11 additions & 11 deletions adm/style/board_notices_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ <h3>{{ lang('WARNING') }}</h3>
<fieldset>
<legend>{{ lang('GENERAL_OPTIONS') }}</legend>
<dl>
<dt><label for="board_notice_enable">{LABEL_BOARD_NOTICE_ACTIVE}{L_COLON}</label></dt>
<dt><label for="board_notice_enable">{{ lang('LABEL_BOARD_NOTICE_ACTIVE') ~ lang('COLON') }}</label></dt>
<dd>
<label><input type="radio" class="radio" id="board_notice_active" name="board_notice_active" value="1"<!-- IF BOARD_NOTICE_ACTIVE --> checked="checked"<!-- ENDIF --> /> {{ lang('YES') }}</label>
<label><input type="radio" class="radio" name="board_notice_active" value="0"<!-- IF not BOARD_NOTICE_ACTIVE --> checked="checked"<!-- ENDIF --> /> {{ lang('NO') }}</label>
</dd>
</dl>
<dl>
<dt><label for="board_notice_title">{LABEL_BOARD_NOTICE_TITLE}{L_COLON}</label><br /><span>{BOARD_NOTICE_TITLE_EXPLAIN}</span></dt>
<dt><label for="board_notice_title">{{ lang('LABEL_BOARD_NOTICE_TITLE') ~ lang('COLON') }}</label><br /><span>{BOARD_NOTICE_TITLE_EXPLAIN}</span></dt>
<dd>
<input name="board_notice_title" type="text" id="board_notice_title" value="{BOARD_NOTICE_TITLE}" size="50" maxlength="100" />
</dd>
Expand All @@ -45,25 +45,25 @@ <h3>{{ lang('WARNING') }}</h3>

{% if BOARD_NOTICE_PREVIEW %}
<fieldset>
<legend>{LABEL_BOARD_NOTICE_PREVIEW}</legend>
<div style="padding:10px; font-size:1.0em; overflow: auto; <!-- IF BOARD_NOTICE_BGCOLOR -->background-color:#{BOARD_NOTICE_BGCOLOR}<!-- ENDIF -->">{BOARD_NOTICE_PREVIEW}</div>
<legend>{{ lang('LABEL_BOARD_NOTICE_PREVIEW') }}</legend>
<div style="padding:10px; font-size:1.0em; overflow: auto; {% if BOARD_NOTICE_BGCOLOR %}background-color:#{{ BOARD_NOTICE_BGCOLOR }}{% endif %}">{{ BOARD_NOTICE_PREVIEW }}</div>
</fieldset>
{% endif %}

<fieldset>
<legend>{LABEL_BOARD_NOTICE_TEXT}</legend>
<legend>{{ lang('LABEL_BOARD_NOTICE_TEXT') }}</legend>
<dl>
<dt><label for="board_notice_bgcolor">{LABEL_BOARD_NOTICE_BGCOLOR}{L_COLON}</label><br /><span>{LABEL_BOARD_NOTICE_BGCOLOR_EXPLAIN}</span></dt>
<dt><label for="board_notice_bgcolor">{{ lang('LABEL_BOARD_NOTICE_BGCOLOR') ~ lang('COLON') }}</label><br /><span>{{ lang('LABEL_BOARD_NOTICE_BGCOLOR_EXPLAIN') }}</span></dt>
<dd>
<input name="board_notice_bgcolor" type="text" id="board_notice_bgcolor" value="{BOARD_NOTICE_BGCOLOR}" size="6" maxlength="6" <!-- IF BOARD_NOTICE_BGCOLOR -->style="border-right:20px solid #{BOARD_NOTICE_BGCOLOR}"<!-- ENDIF --> />
<input name="board_notice_bgcolor" type="text" id="board_notice_bgcolor" value="{BOARD_NOTICE_BGCOLOR}" size="6" maxlength="6" {% if BOARD_NOTICE_BGCOLOR %}style="border-right:20px solid #{{ BOARD_NOTICE_BGCOLOR }}"{% endif %} />
</dd>
</dl>
{% include 'acp_posting_buttons.html' %}

<dl class="responsive-columns">
<dt style="width: 90px;" id="color_palette_placeholder" data-orientation="v" data-height="12" data-width="15" data-bbcode="true"></dt>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px;">
<textarea name="board_notice_text" rows="10" cols="60" style="width: 95%;" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onfocus="initInsertions();" data-bbcode="true">{BOARD_NOTICE_TEXT}</textarea>
<textarea name="board_notice_text" rows="10" cols="60" style="width: 95%;" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onfocus="initInsertions();" data-bbcode="true">{{ BOARD_NOTICE_TEXT }}</textarea>
</dd>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px; margin-top: 5px;">
{% if S_BBCODE_ALLOWED %}
Expand All @@ -76,12 +76,12 @@ <h3>{{ lang('WARNING') }}</h3>
<label><input type="checkbox" class="radio" name="disable_magic_url"{% if S_MAGIC_URL_DISABLE_CHECKED %} checked="checked"{% endif %} /> {{ lang('DISABLE_MAGIC_URL') }}</label>
{% endif %}
</dd>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px; margin-top: 10px;"><strong>{L_OPTIONS}{L_COLON} </strong>{BBCODE_STATUS} :: {IMG_STATUS} :: {FLASH_STATUS} :: {URL_STATUS} :: {SMILIES_STATUS}</dd>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px; margin-top: 10px;"><strong>{L_INFO}{L_COLON} </strong>{VARIABLES_EXPLAIN}</dd>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px; margin-top: 10px;"><strong>{{ lang('OPTIONS') ~ lang('COLON') }} </strong>{{ lang('BBCODE_IS_ON') }} :: {{ lang('IMAGES_ARE_ON') }} :: {{ lang('URL_IS_ON') }} :: {{ lang('SMILIES_ARE_ON') }}</dd>
<dd style="margin-{{ S_CONTENT_FLOW_BEGIN }}: 90px; margin-top: 10px;"><strong>{{ lang('INFORMATION') ~ lang('COLON') }} </strong>{{ lang('VARIABLES_EXPLAIN') }}</dd>
</dl>

<dl>
<dt><label for="board_notice_style">{LABEL_BOARD_NOTICE_STYLE}{L_COLON}</label><br /><span>{LABEL_BOARD_NOTICE_STYLE_EXPLAIN}</span></dt>
<dt><label for="board_notice_style">{{ lang('LABEL_BOARD_NOTICE_STYLE') ~ lang('COLON') }}</label><br /><span>{{ lang('LABEL_BOARD_NOTICE_STYLE_EXPLAIN') }}</span></dt>
<dd>
<input name="board_notice_style" type="text" id="board_notice_style" value="{BOARD_NOTICE_STYLE}" size="20" maxlength="50" />
</dd>
Expand Down
7 changes: 7 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,10 @@ services:
arguments:
- '@fq.boardnotices.service.serializer'
- '@user'

fq.boardnotices.rules.on_board_index:
class: fq\boardnotices\rules\on_board_index
arguments:
- '@fq.boardnotices.service.serializer'
- '@user'
- '@template'
1 change: 1 addition & 0 deletions domain/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class rules
'has_posted_more',
'has_never_posted_in_forum',
'has_posted_in_forum',
'on_board_index',
'in_forum',
'language',
'style',
Expand Down
3 changes: 2 additions & 1 deletion language/en/boardnotices_acp.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
'BOARD_NOTICE_RULE_VALUE' => 'Conditions',
'BOARD_NOTICE_RULE_VARIABLES' => 'Providing',

'NO_GUEST_OR_BOT' => 'No (Guest or Bot)',
'NO_GUEST_OR_BOT' => 'No (Guest or Bot)', // @todo Remove entry

'BOARD_NOTICE_SAVED' => 'Board notice has been saved.',

Expand Down Expand Up @@ -121,6 +121,7 @@
'RULE_LANGUAGE' => "User language is either one of these selected languages",
'RULE_LOGGED_IN' => "Is user logged in",
'RULE_NOT_IN_USERGROUP' => "User does not belong to any of these selected groups",
'RULE_ON_BOARD_INDEX' => "User is browsing the board index",
'RULE_RANK' => "User rank is any of these selected ranks",
'RULE_STYLE' => "User style is either one of these selected styles",

Expand Down
5 changes: 3 additions & 2 deletions language/et/boardnotices_acp.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
'LABEL_BOARD_NOTICES_ACTIVE' => 'Luba foorumi teated',
'BOARD_NOTICES_ACTIVE_EXPLAIN' => 'Siin saate keelata kõigi teadete kuvamise ja samal ajal säilitades laienduse aktiivsena.',

'LABEL_BOARD_NOTICE_DEFAULT_BGCOLOR' => 'Default background color of notices',
'LABEL_BOARD_NOTICE_DEFAULT_BGCOLOR_EXPLAIN' => 'This is the default color of a background message when not specified per notice. If you don\'t set a value, <strong>no</strong> background color will be applied.',
'LABEL_BOARD_NOTICE_DEFAULT_BGCOLOR' => 'Default background color of notices', // @todo
'LABEL_BOARD_NOTICE_DEFAULT_BGCOLOR_EXPLAIN' => 'This is the default color of a background message when not specified per notice. If you don\'t set a value, <strong>no</strong> background color will be applied.', // @todo

'L_FORUMS_VISITS' => 'Külastusi',
'LABEL_FORUMS_VISITS_ACTIVE' => 'Jälgige kuna kasutaja külastas viimati foorumit',
Expand Down Expand Up @@ -119,6 +119,7 @@
'RULE_IN_DEFAULT_USERGROUP' => "Vaikimisi kasutajagrupp on",
'RULE_IN_FORUM' => "Kasutaja sirvib praegu mõnda neist foorumitest",
'RULE_IN_USERGROUP' => "Kasutaja kuulub ühte neist valitud gruppidest",
'RULE_ON_BOARD_INDEX' => "User is browsing the board index", // @todo
'RULE_LANGUAGE' => "Kasutaja keel on üks neist valitud keeltest",
'RULE_LOGGED_IN' => "Kas kasutaja on sisse loginud",
'RULE_NOT_IN_USERGROUP' => "Kasutaja ei kuulu ühtegi valitud gruppi",
Expand Down
2 changes: 1 addition & 1 deletion rules/logged_in.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getDisplayName()

public function getDisplayUnit()
{
return '';
return '(No = Guest or Bot)';
}

public function getType()
Expand Down
80 changes: 80 additions & 0 deletions rules/on_board_index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
*
* Board Notices Manager
*
* @version 1.0.0
* @copyright (c) 2015 Fred Quointeau
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace fq\boardnotices\rules;

use \fq\boardnotices\service\constants;

class on_board_index extends rule_base implements rule_interface
{
/** @var \phpbb\user $lang */
private $user;
/** @var \phpbb\template\template $template */
private $template;

public function __construct(\fq\boardnotices\service\serializer $serializer, \phpbb\user $user, \phpbb\template\template $template)
{
$this->serializer = $serializer;
$this->user = $user;
$this->template = $template;
}

public function getDisplayName()
{
return $this->user->lang('RULE_ON_BOARD_INDEX');
}

public function getDisplayUnit()
{
return '';
}

public function getType()
{
return constants::$RULE_TYPE_YESNO;
}

public function getDefault()
{
return false;
}

public function getPossibleValues()
{
return null;
}

public function validateValues($values)
{
return true;
}

public function isTrue($conditions)
{
$valid = false;
$on_board_index_conditions = $this->validateUniqueCondition($conditions);
$on_board_index = ($this->template->retrieve_var('S_INDEX') === true);
$valid = ($on_board_index_conditions && $on_board_index) || (!$on_board_index_conditions && !$on_board_index);
return $valid;
}

public function getAvailableVars()
{
return array();
}

public function getTemplateVars()
{
return array();
}

}
69 changes: 69 additions & 0 deletions tests/domain/rules_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,73 @@ public function testGetRuleType($rules)

$this->assertEquals("n/a", $rules->getRuleType('mock_rule_1'));
}

/**
* @depends testInstance
* @param fq\boardnotices\domain\rules $rules
*/
public function testGetEmptyRulePossibleValues($rules)
{
global $phpbb_container;

$this->assertNull($rules->getRuleValues('mock_rule_1'));
}

/**
* @depends testInstance
* @param fq\boardnotices\domain\rules $rules
*/
public function testGetRulePossibleValues($rules)
{
global $phpbb_container;

$expected = array('en' => 'English', 'fr' => 'French');
$this->assertEquals($expected, $rules->getRuleValues('mock_rule_2'));
}

/**
* @depends testInstance
* @param fq\boardnotices\domain\rules $rules
*/
public function testGetEmptyDefaultValue($rules)
{
global $phpbb_container;

$this->assertNull($rules->getRuleDefaultValue('mock_rule_1'));
}

/**
* @depends testInstance
* @param fq\boardnotices\domain\rules $rules
*/
public function testGetRuleDefaultValue($rules)
{
global $phpbb_container;

$expected = array(0, 0);
$this->assertEquals($expected, $rules->getRuleDefaultValue('mock_rule_2'));
}

/**
* @depends testInstance
* @param fq\boardnotices\domain\rules $rules
*/
public function testGetEmptyAvailableVariables($rules)
{
global $phpbb_container;

$this->assertEquals(array(), $rules->getAvailableVars('mock_rule_1'));
}

/**
* @depends testInstance
* @param fq\boardnotices\domain\rules $rules
*/
public function testGetRuleAvailableVariables($rules)
{
global $phpbb_container;

$expected = array('{MOCK2}');
$this->assertEquals($expected, $rules->getAvailableVars('mock_rule_2'));
}
}
9 changes: 1 addition & 8 deletions tests/mock_rules/mock_rule_1.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ public function __construct(\fq\boardnotices\service\serializer $serializer)
$this->serializer = $serializer;
}

private function setTemplateVars($value)
{
$this->template_vars = array(
'MOCK1' => $value
);
}

public function getDisplayName()
{
return "Mock Rule 1";
Expand Down Expand Up @@ -65,7 +58,7 @@ public function isTrue($conditions)

public function getAvailableVars()
{
return array('MOCK1');
return array();
}

public function getTemplateVars()
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_rules/mock_rule_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function getType()

public function getDefault()
{
return null;
return array(0, 0);
}

public function getPossibleValues()
{
return null;
return array('en' => 'English', 'fr' => 'French');
}

public function validateValues($values)
Expand Down

0 comments on commit 7081e39

Please sign in to comment.