From 052efa66030e885e4bae3354f6a2e57e186b4ab6 Mon Sep 17 00:00:00 2001 From: Jonathan Holvey Date: Sat, 11 Nov 2017 11:38:52 +1000 Subject: [PATCH 1/2] Add category description field to edit category admin page --- bl-kernel/abstract/dblist.class.php | 15 ++++++++++++--- bl-kernel/admin/controllers/edit-category.php | 2 +- bl-kernel/admin/views/edit-category.php | 7 +++++++ bl-kernel/functions.php | 5 +++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bl-kernel/abstract/dblist.class.php b/bl-kernel/abstract/dblist.class.php index a1b2ae1f..92f5b406 100644 --- a/bl-kernel/abstract/dblist.class.php +++ b/bl-kernel/abstract/dblist.class.php @@ -102,13 +102,16 @@ class dbList extends dbJSON return $this->save(); } - public function edit($oldKey, $newName) + public function edit($oldKey, $newName, $properties) { $newKey = $this->generateKey($newName); $this->db[$newKey]['name'] = Sanitize::html($newName); $this->db[$newKey]['list'] = $this->db[$oldKey]['list']; + foreach ($properties as $propertyKey => $propertyValue) + $this->db[$newKey][$propertyKey] = Sanitize::html($propertyValue); + // Remove the old key if( $oldKey != $newKey ) { 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 public function getName($key) { - if( isset($this->db[$key]) ) { - return $this->db[$key]['name']; + return $this->getProperty($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; diff --git a/bl-kernel/admin/controllers/edit-category.php b/bl-kernel/admin/controllers/edit-category.php index f93e541c..a579c9b0 100644 --- a/bl-kernel/admin/controllers/edit-category.php +++ b/bl-kernel/admin/controllers/edit-category.php @@ -26,7 +26,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { deleteCategory($_POST['categoryKey']); } elseif (isset($_POST['edit'])) { - editCategory($_POST['categoryKey'], $_POST['category']); + editCategory($_POST['categoryKey'], $_POST['category'], $_POST['categoryDescription']); } Redirect::page('categories'); diff --git a/bl-kernel/admin/views/edit-category.php b/bl-kernel/admin/views/edit-category.php index 70f660c9..2941fe44 100644 --- a/bl-kernel/admin/views/edit-category.php +++ b/bl-kernel/admin/views/edit-category.php @@ -21,6 +21,13 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); '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 '
diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 2e05710b..164c8e96 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -662,7 +662,7 @@ function createCategory($category) { return false; } -function editCategory($oldCategoryKey, $newCategory) { +function editCategory($oldCategoryKey, $newCategory, $newDescription) { global $Language; global $dbPages; global $dbCategories; @@ -673,7 +673,8 @@ function editCategory($oldCategoryKey, $newCategory) { 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')); return false; } From e36ce4328c68d7a617f4ea4e2f7073ca385686d9 Mon Sep 17 00:00:00 2001 From: Jonathan Holvey Date: Sat, 11 Nov 2017 16:52:40 +1000 Subject: [PATCH 2/2] Add function for accessing category description from page object --- bl-kernel/page.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index 5efdd1ad..5f79d2d2 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -222,6 +222,13 @@ class Page { return $this->getValue('category'); } + // Returns the category description + public function categoryDescription() + { + global $dbCategories; + return $dbCategories->getProperty($this->categoryKey(), 'description'); + } + // Returns the field from the array // categoryMap = array( 'name'=>'', 'list'=>array() ) public function categoryMap($field)