namespace wcf\data\acl\option;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\system\acl\ACLHandler;
-use wcf\system\exception\UserInputException;
/**
* Executes acl option-related actions.
*
- * @author Marcel Werk
- * @copyright 2001-2012 WoltLab GmbH
+ * @author Alexander Ebert
+ * @copyright 2001-2013 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage data.acl.option
* Validates parameters for ACL options.
*/
public function validateLoadAll() {
- if (!isset($this->parameters['data']['objectTypeID'])) {
- throw new UserInputException('objectTypeID');
- }
+ $this->readInteger('objectID', true);
+ $this->readInteger('objectTypeID');
+ $this->readString('categoryName', true);
}
/**
* @return array
*/
public function loadAll() {
- $objectIDs = (isset($this->parameters['data']['objectID'])) ? array($this->parameters['data']['objectID']) : array();
- $permissions = ACLHandler::getInstance()->getPermissions($this->parameters['data']['objectTypeID'], $objectIDs, null, true);
+ $objectIDs = (isset($this->parameters['objectID'])) ? array($this->parameters['objectID']) : array();
+ $permissions = ACLHandler::getInstance()->getPermissions($this->parameters['objectTypeID'], $objectIDs, $this->parameters['categoryName'], true);
return $permissions;
}
use wcf\system\exception\SystemException;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
+use wcf\util\StringUtil;
/**
* Handles ACL permissions.
/**
* Returns a list of permissions by object type id.
*
- * @param integer $objectTypeID
- * @param array $objectIDs
- * @param wcf\data\acl\option\category\ACLOptionCategory $category
- * @param boolean $settingsView
+ * @param integer $objectTypeID
+ * @param array $objectIDs
+ * @param string $categoryName
+ * @param boolean $settingsView
* @return array
*/
- public function getPermissions($objectTypeID, array $objectIDs, ACLOptionCategory $category = null, $settingsView = false) {
- $optionList = $this->getOptions($objectTypeID, $category);
+ public function getPermissions($objectTypeID, array $objectIDs, $categoryName = '', $settingsView = false) {
+ $optionList = $this->getOptions($objectTypeID, $categoryName);
$data = array(
'options' => $optionList,
$data['options'] = array();
$data['categories'] = array();
- $categoryNames = array();
- foreach ($optionList as $option) {
- $data['options'][$option->optionID] = array(
- 'categoryName' => $option->categoryName,
- 'label' => WCF::getLanguage()->get('wcf.acl.option.'.$objectType->objectType.'.'.$option->optionName),
- 'optionName' => $option->optionName
- );
+ if (count($optionList)) {
+ $categoryNames = array();
+ foreach ($optionList as $option) {
+ $data['options'][$option->optionID] = array(
+ 'categoryName' => $option->categoryName,
+ 'label' => WCF::getLanguage()->get('wcf.acl.option.'.$objectType->objectType.'.'.$option->optionName),
+ 'optionName' => $option->optionName
+ );
+
+ if (!in_array($option->categoryName, $categoryNames)) {
+ $categoryNames[] = $option->categoryName;
+ }
+ }
- if (!in_array($option->categoryName, $categoryNames)) {
- $categoryNames[] = $option->categoryName;
+ // load categories
+ $categoryList = new ACLOptionCategoryList();
+ $categoryList->getConditionBuilder()->add("acl_option_category.categoryName IN (?)", array($categoryNames));
+ $categoryList->getConditionBuilder()->add("acl_option_category.objectTypeID = ?", array($objectTypeID));
+ $categoryList->readObjects();
+
+ foreach ($categoryList as $category) {
+ $data['categories'][$category->categoryName] = WCF::getLanguage()->get('wcf.acl.option.category.'.$objectType->objectType.'.'.$category->categoryName);
}
}
-
- // load categories
- $categoryList = new ACLOptionCategoryList();
- $categoryList->getConditionBuilder()->add("acl_option_category.categoryName IN (?)", array($categoryNames));
- $categoryList->getConditionBuilder()->add("acl_option_category.objectTypeID = ?", array($objectTypeID));
- $categoryList->readObjects();
-
- foreach ($categoryList as $category) {
- $data['categories'][$category->categoryName] = WCF::getLanguage()->get('wcf.acl.option.category.'.$objectType->objectType.'.'.$category->categoryName);
- }
}
return $data;
$optionsIDs[] = $option->optionID;
}
+ // category matched no options
+ if (empty($optionsIDs)) {
+ return;
+ }
+
$columnID = $type.'ID';
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("optionID IN (?)", array($optionsIDs));
/**
* Returns a list of options by object type id.
*
- * @param integer $objectTypeID
- * @param wcf\data\acl\option\category\ACLOptionCategory $category
+ * @param integer $objectTypeID
+ * @param string $categoryName
* @return wcf\data\acl\option\ACLOptionList
*/
- public function getOptions($objectTypeID, ACLOptionCategory $category = null) {
+ public function getOptions($objectTypeID, $categoryName = '') {
$optionList = new ACLOptionList();
- if ($category !== null) {
- $optionList->getConditionBuilder()->add("acl_option.categoryName = ?", array($category->categoryName));
+ if (!empty($categoryName)) {
+ if (StringUtil::endsWith($categoryName, '.*')) {
+ $categoryName = StringUtil::substring($categoryName, 0, -1) . '%';
+ $optionList->getConditionBuilder()->add("acl_option.categoryName LIKE ?", array($categoryName));
+ }
+ else {
+ $optionList->getConditionBuilder()->add("acl_option.categoryName = ?", array($category->categoryName));
+ }
}
$optionList->getConditionBuilder()->add("acl_option.objectTypeID = ?", array($objectTypeID));
$optionList->readObjects();