/** * 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); } }
/** * 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; } }