/** * * * @param array $category */ function writeCategoryOptions($category) { $cdd = new DropdownModule('', '', 'dropdown-category-options', 'dropdown-menu-right'); $cdd->setTrigger(displayAsSymbol($category['DisplayAs']), 'button', 'btn'); $cdd->setView('dropdown-twbs'); $cdd->setForceDivider(true); $cdd->addGroup('', 'edit')->addLink(t('View'), $category['Url'], 'edit.view')->addLink(t('Edit'), "/vanilla/settings/editcategory?categoryid={$category['CategoryID']}", 'edit.edit'); $cdd->addGroup(t('Display as'), 'displayas'); foreach (CategoryModel::getDisplayAsOptions() as $displayAs => $label) { $cssClass = strcasecmp($displayAs, $category['DisplayAs']) === 0 ? 'selected' : ''; $icon = displayAsSymbol($displayAs); $cdd->addLink(t($label), '#', 'displayas.' . strtolower($displayAs), 'js-displayas ' . $cssClass, [], ['icon' => $icon, 'attributes' => ['data-displayas' => strtolower($displayAs)]], false); } $cdd->addGroup('', 'actions')->addLink(t('Add Subcategory'), "/vanilla/settings/addcategory?parent={$category['CategoryID']}", 'actions.add'); $cdd->addGroup('', 'delete')->addLink(t('Delete'), "/vanilla/settings/deletecategory?categoryid={$category['CategoryID']}", 'delete.delete', 'js-modal'); echo $cdd->toString(); }
/** * Adding a new category. * * @since 2.0.0 * @access public */ public function addCategory($parent = '') { // Check permission $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false); // Set up head $this->addJsFile('jquery.alphanumeric.js'); $this->addJsFile('manage-categories.js'); $this->addJsFile('jquery.gardencheckboxgrid.js'); $this->title(t('Add Category')); $this->setHighlightRoute('vanilla/settings/categories'); // Prep models $RoleModel = new RoleModel(); $PermissionModel = Gdn::permissionModel(); $this->Form->setModel($this->CategoryModel); // Load all roles with editable permissions. $this->RoleArray = $RoleModel->getArray(); $this->fireAs('SettingsController'); $this->fireEvent('AddEditCategory'); $this->setupDiscussionTypes(array()); $displayAsOptions = CategoryModel::getDisplayAsOptions(); if ($this->Form->authenticatedPostBack()) { // Form was validly submitted $IsParent = $this->Form->getFormValue('IsParent', '0'); $this->Form->setFormValue('AllowDiscussions', $IsParent == '1' ? '0' : '1'); $this->Form->setFormValue('CustomPoints', (bool) $this->Form->getFormValue('CustomPoints')); // Enforces tinyint values on boolean fields to comply with strict mode $this->Form->setFormValue('HideAllDiscussions', forceBool($this->Form->getFormValue('HideAllDiscussions'), '0', '1', '0')); $this->Form->setFormValue('Archived', forceBool($this->Form->getFormValue('Archived'), '0', '1', '0')); $this->Form->setFormValue('AllowFileUploads', forceBool($this->Form->getFormValue('AllowFileUploads'), '0', '1', '0')); $upload = new Gdn_Upload(); $tmpImage = $upload->validateUpload('PhotoUpload', false); if ($tmpImage) { // Generate the target image name $targetImage = $upload->generateTargetName(PATH_UPLOADS); $imageBaseName = pathinfo($targetImage, PATHINFO_BASENAME); // Save the uploaded image $parts = $upload->saveAs($tmpImage, $imageBaseName); $this->Form->setFormValue('Photo', $parts['SaveName']); } $CategoryID = $this->Form->save(); if ($CategoryID) { $Category = CategoryModel::categories($CategoryID); $this->setData('Category', $Category); if ($this->deliveryType() == DELIVERY_TYPE_ALL) { redirect('vanilla/settings/categories'); } elseif ($this->deliveryType() === DELIVERY_TYPE_DATA && method_exists($this, 'getCategory')) { $this->Data = []; $this->getCategory($CategoryID); return; } } else { unset($CategoryID); } } else { if ($parent) { $category = CategoryModel::categories($parent); if ($category) { $this->Form->setValue('ParentCategoryID', $category['CategoryID']); if (val('DisplayAs', $category) === 'Flat') { unset($displayAsOptions['Heading']); } } } $this->Form->addHidden('CodeIsDefined', '0'); } // Get all of the currently selected role/permission combinations for this junction. $Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => isset($CategoryID) ? $CategoryID : 0), 'Category'); $Permissions = $PermissionModel->unpivotPermissions($Permissions, true); if ($this->deliveryType() == DELIVERY_TYPE_ALL) { $this->setData('PermissionData', $Permissions, true); } $this->setData('Operation', 'Add'); $this->setData('DisplayAsOptions', $displayAsOptions); $this->render('editcategory', 'vanillasettings', 'vanilla'); }