/** * Installs user option categories. * * @param array $category * @param array $categoryXML */ protected function saveCategory($category, $categoryXML = null) { $icon = $menuIcon = ''; if (isset($categoryXML['icon'])) { $icon = $categoryXML['icon']; } if (isset($categoryXML['menuicon'])) { $menuIcon = $categoryXML['menuicon']; } // use for create and update $data = array('parentCategoryName' => $category['parentCategoryName'], 'categoryIconS' => $menuIcon, 'categoryIconM' => $icon, 'permissions' => $category['permissions'], 'options' => $category['options']); // append show order if explicitly stated if ($category['showOrder'] !== null) { $data['showOrder'] = $category['showOrder']; } $userOptionCategory = UserOptionCategory::getCategoryByName($category['categoryName'], $this->installation->getPackageID()); if ($userOptionCategory->categoryID) { $categoryEditor = new UserOptionCategoryEditor($userOptionCategory); $categoryEditor->update($data); } else { // append data fields for create $data['packageID'] = $this->installation->getPackageID(); $data['categoryName'] = $category['categoryName']; UserOptionCategoryEditor::create($data); } }
/** * @see \wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveCategory() */ protected function saveCategory($category, $categoryXML = null) { // use for create and update $data = array('parentCategoryName' => $category['parentCategoryName'], 'permissions' => $category['permissions'], 'options' => $category['options']); // append show order if explicitly stated if ($category['showOrder'] !== null) { $data['showOrder'] = $category['showOrder']; } $userOptionCategory = UserOptionCategory::getCategoryByName($category['categoryName']); if ($userOptionCategory !== null) { if ($userOptionCategory->packageID != $this->installation->getPackageID()) { throw new SystemException("Cannot override existing category '" . $category['categoryName'] . "'"); } $categoryEditor = new UserOptionCategoryEditor($userOptionCategory); $categoryEditor->update($data); } else { // append data fields for create $data['packageID'] = $this->installation->getPackageID(); $data['categoryName'] = $category['categoryName']; UserOptionCategoryEditor::create($data); } }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); // save label $this->objectAction = new UserOptionCategoryAction(array(), 'create', array('data' => array_merge($this->additionalFields, array('parentCategoryName' => 'profile', 'categoryName' => $this->categoryName, 'showOrder' => $this->showOrder)))); $this->objectAction->executeAction(); // update name $returnValues = $this->objectAction->getReturnValues(); $categoryID = $returnValues['returnValues']->categoryID; I18nHandler::getInstance()->save('categoryName', 'wcf.user.option.category.category' . $categoryID, 'wcf.user.option'); $categoryEditor = new UserOptionCategoryEditor($returnValues['returnValues']); $categoryEditor->update(array('categoryName' => 'category' . $categoryID)); $this->saved(); // reset values $this->categoryName = ''; $this->showOrder = 0; I18nHandler::getInstance()->reset(); // show success WCF::getTPL()->assign(array('success' => true)); }
/** * Creates the given category if necessary. * * @param string $name */ protected function createCategory($name) { if ($this->categoryCache === null) { // get existing categories $list = new UserOptionCategoryList(); $list->getConditionBuilder()->add('categoryName = ? OR parentCategoryName = ?', array('profile', 'profile')); $list->readObjects(); foreach ($list->getObjects() as $category) { $this->categoryCache[] = $category->categoryName; } } if (!in_array($name, $this->categoryCache)) { // create category UserOptionCategoryEditor::create(array('packageID' => 1, 'categoryName' => $name, 'parentCategoryName' => 'profile')); $this->categoryCache[] = $name; } }