Add category description field to edit category admin page

This commit is contained in:
Jonathan Holvey 2017-11-11 11:38:52 +10:00
parent 3f3fde21e9
commit 052efa6603
4 changed files with 23 additions and 6 deletions

View File

@ -102,13 +102,16 @@ class dbList extends dbJSON
return $this->save(); return $this->save();
} }
public function edit($oldKey, $newName) public function edit($oldKey, $newName, $properties)
{ {
$newKey = $this->generateKey($newName); $newKey = $this->generateKey($newName);
$this->db[$newKey]['name'] = Sanitize::html($newName); $this->db[$newKey]['name'] = Sanitize::html($newName);
$this->db[$newKey]['list'] = $this->db[$oldKey]['list']; $this->db[$newKey]['list'] = $this->db[$oldKey]['list'];
foreach ($properties as $propertyKey => $propertyValue)
$this->db[$newKey][$propertyKey] = Sanitize::html($propertyValue);
// Remove the old key // Remove the old key
if( $oldKey != $newKey ) { if( $oldKey != $newKey ) {
unset( $this->db[$oldKey] ); unset( $this->db[$oldKey] );
@ -129,8 +132,14 @@ class dbList extends dbJSON
// Returns the name associated to the key, FALSE if the key doesn't exist // Returns the name associated to the key, FALSE if the key doesn't exist
public function getName($key) public function getName($key)
{ {
if( isset($this->db[$key]) ) { return $this->getProperty($key, 'name');
return $this->db[$key]['name']; }
// Returns a property associated to the key, FALSE if the key doesn't exist
public function getProperty($key, $property)
{
if( isset($this->db[$key]) && isset($this->db[$key][$property])) {
return $this->db[$key][$property];
} }
return false; return false;

View File

@ -26,7 +26,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
deleteCategory($_POST['categoryKey']); deleteCategory($_POST['categoryKey']);
} }
elseif (isset($_POST['edit'])) { elseif (isset($_POST['edit'])) {
editCategory($_POST['categoryKey'], $_POST['category']); editCategory($_POST['categoryKey'], $_POST['category'], $_POST['categoryDescription']);
} }
Redirect::page('categories'); Redirect::page('categories');

View File

@ -21,6 +21,13 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'class'=>'uk-width-1-2 uk-form-medium' 'class'=>'uk-width-1-2 uk-form-medium'
)); ));
HTML::formTextArea(array(
'name'=>'categoryDescription',
'label'=>$L->g('Description'),
'value'=>$dbCategories->getProperty($categoryKey, 'description'),
'class'=>'uk-width-1-2 uk-form-medium'
));
echo '<div class="uk-form-row"> echo '<div class="uk-form-row">
<div class="uk-form-controls"> <div class="uk-form-controls">
<button type="submit" name="edit" class="uk-button uk-button-primary">'.$L->g('Save').'</button> <button type="submit" name="edit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>

View File

@ -662,7 +662,7 @@ function createCategory($category) {
return false; return false;
} }
function editCategory($oldCategoryKey, $newCategory) { function editCategory($oldCategoryKey, $newCategory, $newDescription) {
global $Language; global $Language;
global $dbPages; global $dbPages;
global $dbCategories; global $dbCategories;
@ -673,7 +673,8 @@ function editCategory($oldCategoryKey, $newCategory) {
return false; return false;
} }
if( $dbCategories->edit($oldCategoryKey, $newCategory) == false ) { $properties = array('description' => $newDescription);
if( $dbCategories->edit($oldCategoryKey, $newCategory, $properties) == false ) {
Alert::set($Language->g('Already exist a category')); Alert::set($Language->g('Already exist a category'));
return false; return false;
} }