<?php
namespace wcf\system\condition;
use wcf\data\condition\Condition;
+use wcf\system\exception\UserInputException;
use wcf\system\WCF;
use wcf\util\UserUtil;
/**
* Condition implementation if it is the active user uses a mobile browser.
*
- * @author Matthias Schmidt
+ * @author Matthias Schmidt, Joshua Rüsweg
* @copyright 2001-2014 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.condition
* @category Community Framework
*/
-class UserMobileBrowserCondition extends AbstractCondition implements IContentCondition {
+class UserMobileBrowserCondition extends AbstractSingleFieldCondition implements IContentCondition {
+ /**
+ * @see \wcf\system\condition\AbstractSingleFieldCondition::$label
+ */
+ protected $label = 'wcf.user.condition.mobileBrowser';
+
/**
* 1 if mobile browser checkbox is checked
* @var integer
*/
protected $usesMobileBrowser = 0;
+ /**
+ * 1 if not use mobile browser checkbox is checked
+ * @var integer
+ */
+ protected $usesNoMobileBrowser = 0;
+
/**
* @see \wcf\system\condition\ICondition::getData()
*/
public function getData() {
- if ($this->usesMobileBrowser) {
+ if ($this->usesMobileBrowser || $this->usesNoMobileBrowser) {
return array(
- 'usesMobileBrowser' => 1
+ // if notUseMobileBrowser is selected usesMobileBrowser is 0
+ // otherwise notUseMobileBrowser is 1
+ 'usesMobileBrowser' => $this->usesMobileBrowser
);
}
/**
* @see \wcf\system\condition\ICondition::getHTML()
*/
- public function getHTML() {
- $label = WCF::getLanguage()->get('wcf.user.condition.usesMobileBrowser');
- $checked = '';
+ public function getFieldElement() {
+ $usesMobileBrowserLabel = WCF::getLanguage()->get('wcf.user.condition.mobileBrowser.usesMobileBrowser');
+ $usesNoMobileBrowserLabel = WCF::getLanguage()->get('wcf.user.condition.mobileBrowser.usesNoMobileBrowser');
+ $usesMobileBrowserChecked = '';
if ($this->usesMobileBrowser) {
- $checked = ' checked="checked"';
+ $usesMobileBrowserChecked = ' checked="checked"';
+ }
+
+ $usesNoMobileBrowserChecked = '';
+ if ($this->usesNoMobileBrowser) {
+ $usesNoMobileBrowserChecked = ' checked="checked"';
}
return <<<HTML
-<dl>
- <dt></dt>
- <dd>
- <label><input type="checkbox" name="usesMobileBrowser" id="usesMobileBrowser"{$checked} /> {$label}</label>
- </dd>
-</dl>
+ <label><input type="checkbox" name="usesMobileBrowser" id="usesMobileBrowser"{$usesMobileBrowserChecked} /> {$usesMobileBrowserLabel}</label>
+ <label><input type="checkbox" name="usesNoMobileBrowser" id="usesNoMobileBrowser"{$usesNoMobileBrowserChecked} /> {$usesNoMobileBrowserLabel}</label>
HTML;
}
*/
public function readFormParameters() {
if (isset($_POST['usesMobileBrowser'])) $this->usesMobileBrowser = 1;
+ if (isset($_POST['usesNoMobileBrowser'])) $this->usesNoMobileBrowser = 1;
}
/**
*/
public function reset() {
$this->usesMobileBrowser = 0;
+ $this->usesNoMobileBrowser = 0;
}
/**
- * @see \wcf\system\condition\ICondition::readFormParameters()
+ * @see \wcf\system\condition\ICondition::setData()
*/
public function setData(Condition $condition) {
$this->usesMobileBrowser = $condition->usesMobileBrowser;
+ $this->usesNoMobileBrowser = !$condition->usesMobileBrowser;
+ }
+
+ /**
+ * @see \wcf\system\condition\ICondition::validate()
+ */
+ public function validate() {
+ if ($this->usesMobileBrowser && $this->usesNoMobileBrowser) {
+ $this->errorMessage = 'wcf.user.condition.mobileBrowser.usesMobileBrowser.error.conflict';
+
+ throw new UserInputException('mobileBrowser', 'conflict');
+ }
}
/**
* @see \wcf\system\condition\IContentCondition::showContent()
*/
public function showContent(Condition $condition) {
- return UserUtil::usesMobileBrowser();
+ return (($condition->usesMobileBrowser && UserUtil::usesMobileBrowser()) || (!$condition->usesMobileBrowser && !UserUtil::usesMobileBrowser()));
}
}
<item name="wcf.user.condition.groupIDs.description"><![CDATA[Benutzer müssen in den ausgewählten Benutzergruppen Mitglied sein.]]></item>
<item name="wcf.user.condition.languages"><![CDATA[Sprachen]]></item>
<item name="wcf.user.condition.likesReceived"><![CDATA[Erhaltene Likes]]></item>
+ <item name="wcf.user.condition.mobileBrowser"><![CDATA[Mobiler Browser]]></item>
+ <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser"><![CDATA[Verwendet mobilen Browser]]></item>
+ <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser.error.conflict"><![CDATA[„Verwendet mobilen Browser“ und „Verwendet keinen mobilen Browser“ können nicht gleichzeitig ausgewählt werden.]]></item>
+ <item name="wcf.user.condition.mobileBrowser.usesNoMobileBrowser"><![CDATA[Verwendet keinen mobilen Browser]]></item>
<item name="wcf.user.condition.notGroupIDs"><![CDATA[nicht in Benutzergruppen]]></item>
<item name="wcf.user.condition.notGroupIDs.description"><![CDATA[Benutzer dürfen in den ausgewählten Benutzergruppen nicht Mitglied sein.]]></item>
<item name="wcf.user.condition.notGroupIDs.error.groupIDsIntersection"><![CDATA[Die ausgewählten Benutzergruppen in „in Benutzergruppen“ und „nicht in Benutzergruppen“ sind widersprüchlich.]]></item>
<item name="wcf.user.condition.state.isEnabled"><![CDATA[Aktiviert]]></item>
<item name="wcf.user.condition.state.isEnabled.error.conflict"><![CDATA[„Aktiviert“ und „Nicht aktiviert“ können nicht gleichzeitig ausgewählt werden.]]></item>
<item name="wcf.user.condition.state.isNotBanned"><![CDATA[Nicht gesperrt]]></item>
- <item name="wcf.user.condition.usesMobileBrowser"><![CDATA[Verwendet mobilen Browser]]></item>
</category>
<category name="wcf.user.notification">
<item name="wcf.user.condition.groupIDs.description"><![CDATA[Users have to be a member of the selected user groups.]]></item>
<item name="wcf.user.condition.languages"><![CDATA[Languages]]></item>
<item name="wcf.user.condition.likesReceived"><![CDATA[Likes Received]]></item>
+ <item name="wcf.user.condition.mobileBrowser"><![CDATA[Mobile browser]]></item>
+ <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser"><![CDATA[Uses mobile browser]]></item>
+ <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser.error.conflict"><![CDATA[You may not simultaneously select “Uses mobile browser“ and “Uses no mobile browser“.]]]></item>
+ <item name="wcf.user.condition.mobileBrowser.usesNoMobileBrowser"><![CDATA[Uses no mobile browser]]></item>
<item name="wcf.user.condition.notGroupIDs"><![CDATA[not in User Groups]]></item>
<item name="wcf.user.condition.notGroupIDs.description"><![CDATA[Users may not be a member of the selected user groups.]]></item>
<item name="wcf.user.condition.notGroupIDs.error.groupIDsIntersection"><![CDATA[The selected user groups in “in User Groups“ and “not in User Groups“ are conflicting.]]></item>
<item name="wcf.user.condition.state.isEnabled"><![CDATA[Approved]]></item>
<item name="wcf.user.condition.state.isEnabled.error.conflict"><![CDATA[You may not simultaneously select “Approved“ and “Awaiting Approval“.]]></item>
<item name="wcf.user.condition.state.isNotBanned"><![CDATA[Not Banned]]></item>
- <item name="wcf.user.condition.usesMobileBrowser"><![CDATA[Uses mobile browser]]></item>
</category>
<category name="wcf.user.notification">