예제 #1
0
 public function add($param = array())
 {
     $id = $backurl = 0;
     list($id, $backurl) = $param;
     $parentMenu = $this->showCategoryModel->getChildCategoryById(0);
     $categoryModel = new categoryModel();
     $trueCategoryList = $categoryModel->getChildCategoryByIdCache(0);
     $data = array('parentMenu' => $parentMenu, 'id' => $id, 'backurl' => $backurl, 'trueCategoryList' => $trueCategoryList);
     $this->setView($data);
 }
예제 #2
0
<?php

$categoryModel = new categoryModel();
if (!empty($_POST)) {
    #Guardar formulario
    if ($_POST['act'] == 'save') {
        $categoryModel->cargarPorId($_POST['idcategory']);
        $categoryModel->setValues($_POST);
        $categoryModel->save();
        die(json_encode(array('msg' => 'El registro fue guardado correctamente', 'type' => 'success')));
    }
    #Listar datatable
    if ($_POST['act'] == 'listar') {
        $pager = $categoryModel->getPager(array('idcategory', 'name'));
        die($pager->getJSON());
    }
    #Eliminar registro
    if ($_POST['act'] == 'delete') {
        $categoryModel->cargarPorId($_POST['id']);
        $categoryModel->delete();
        die(json_encode(array('msg' => 'El registro fue eliminado correctamente', 'type' => 'success')));
    }
    #cargar para editar registro
    if ($_POST['act'] == 'edit') {
        die(json_encode(array('data' => $categoryModel->cargarPorId($_POST['id']))));
    }
} else {
    echo $engine->render('category', $aParams);
    exit;
}
 /**
  * Editing a category.
  *
  * @since 2.0.0
  * @param int|string $CategoryID Unique ID of the category to be updated.
  * @throws Exception when category cannot be found.
  */
 public function editCategory($CategoryID = '')
 {
     // Check permission
     $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
     // Set up models
     $RoleModel = new RoleModel();
     $PermissionModel = Gdn::permissionModel();
     $this->Form->setModel($this->CategoryModel);
     if (!$CategoryID && $this->Form->authenticatedPostBack()) {
         if ($ID = $this->Form->getFormValue('CategoryID')) {
             $CategoryID = $ID;
         }
     }
     // Get category data
     $this->Category = CategoryModel::categories($CategoryID);
     if (!$this->Category) {
         throw notFoundException('Category');
     }
     // Category data is expected to be in the form of an object.
     $this->Category = (object) $this->Category;
     $this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
     $displayAsOptions = categoryModel::getDisplayAsOptions();
     // Restrict "Display As" types based on parent.
     $parentCategory = $this->CategoryModel->getID($this->Category->ParentCategoryID);
     $parentDisplay = val('DisplayAs', $parentCategory);
     if ($parentDisplay === 'Flat') {
         unset($displayAsOptions['Heading']);
     }
     // Set up head
     $this->addJsFile('jquery.alphanumeric.js');
     $this->addJsFile('manage-categories.js');
     $this->addJsFile('jquery.gardencheckboxgrid.js');
     $this->title(t('Edit Category'));
     $this->setHighlightRoute('vanilla/settings/categories');
     // Make sure the form knows which item we are editing.
     $this->Form->addHidden('CategoryID', $CategoryID);
     $this->setData('CategoryID', $CategoryID);
     // Load all roles with editable permissions
     $this->RoleArray = $RoleModel->getArray();
     $this->fireAs('SettingsController');
     $this->fireEvent('AddEditCategory');
     if ($this->Form->authenticatedPostBack()) {
         $this->setupDiscussionTypes($this->Category);
         $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']);
         }
         $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'));
         if ($parentDisplay === 'Flat' && $this->Form->getFormValue('DisplayAs') === 'Heading') {
             $this->Form->addError('Cannot display as a heading when your parent category is displayed flat.', 'DisplayAs');
         }
         if ($this->Form->save()) {
             $Category = CategoryModel::categories($CategoryID);
             $this->setData('Category', $Category);
             if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
                 $destination = $this->categoryPageByParent($parentCategory);
                 redirect($destination);
             } elseif ($this->deliveryType() === DELIVERY_TYPE_DATA && method_exists($this, 'getCategory')) {
                 $this->Data = [];
                 $this->getCategory($CategoryID);
                 return;
             }
         }
     } else {
         $this->Form->setData($this->Category);
         $this->setupDiscussionTypes($this->Category);
         $this->Form->setValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
     }
     // Get all of the currently selected role/permission combinations for this junction.
     $Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
     $Permissions = $PermissionModel->unpivotPermissions($Permissions, true);
     if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
         $this->setData('PermissionData', $Permissions, true);
     }
     // Render default view
     $this->setData('Operation', 'Edit');
     $this->setData('DisplayAsOptions', $displayAsOptions);
     $this->render();
 }
예제 #4
0
 private function category($num = 0)
 {
     $str = null;
     $category = new categoryModel();
     foreach ($category->getAllCategory() as $key => $value) {
         if ($num == $value->id) {
             $selected = "selected='selected'";
         } else {
             $selected = '';
         }
         $str .= "<option value='" . $value->id . "' " . $selected . ">" . $value->name . "</option>";
     }
     $this->smarty->assign("category", $str);
 }
예제 #5
0
 private function mall($num = 0)
 {
     $category = new categoryModel();
     //Tools::dump($nav->getAllProducts());
     $str = null;
     foreach ($category->getAllCategory() as $value) {
         //Tools::dump($value);
         $selected = null;
         if ($num == $value->id) {
             $selected = "selected='selected'";
         } else {
             $selected = "";
         }
         $str .= "<option value='" . $value->id . "' " . $selected . ">" . $value->name . "</option>";
     }
     $this->smarty->assign("category", $str);
 }