From 30da98f0a36bfe38798de62a853b3d4081a8a115 Mon Sep 17 00:00:00 2001 From: Patrick Barroca <pbarroca@afi-sa.fr> Date: Thu, 14 Jun 2018 11:11:09 +0200 Subject: [PATCH] dev #75882 refacto trait tree --- library/Class/ArticleCategorie.php | 15 -------------- library/Class/SitothequeCategorie.php | 15 -------------- library/Class/UserGroupCategorie.php | 22 +-------------------- library/Trait/Tree.php | 26 +++++++++++++++++++++++++ library/Trait/TreeNode.php | 14 ++++++++----- library/Trait/TreeViewableCategorie.php | 16 ++++++++++++--- library/Trait/TreeViewableItem.php | 14 +++++++++++-- 7 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 library/Trait/Tree.php diff --git a/library/Class/ArticleCategorie.php b/library/Class/ArticleCategorie.php index c26f66721b4..17c9b9fad4e 100644 --- a/library/Class/ArticleCategorie.php +++ b/library/Class/ArticleCategorie.php @@ -122,27 +122,12 @@ class Class_ArticleCategorie extends Storm_Model_Abstract { } - /** [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][voir Trait_TreeNode]] */ - public function getParent() { - return $this->getParentCategorie(); - } - - /** [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][voir Trait_TreeNode]] */ public function getParentIdFieldName() { return 'id_cat_mere'; } - /** - * cf [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][Trait_TreeNode]] - */ - public function getChildren() { - return $this->getSousCategories(); - } - - - public function getRecursiveSousCategories() { $all_categories = $sous_categories = $this->getSousCategories(); foreach ($sous_categories as $categorie) diff --git a/library/Class/SitothequeCategorie.php b/library/Class/SitothequeCategorie.php index 0a43ebb7f28..bb9d1ba4967 100644 --- a/library/Class/SitothequeCategorie.php +++ b/library/Class/SitothequeCategorie.php @@ -45,27 +45,12 @@ class Class_SitothequeCategorie extends Storm_Model_Abstract { 'id_site' => 0]; - /** [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][voir Trait_TreeNode]] */ - public function getParent() { - return $this->getParentCategorie(); - } - - /** [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][voir Trait_TreeNode]] */ public function getParentIdFieldName() { return 'id_cat_mere'; } - /** - * cf [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][Trait_TreeNode]] - */ - public function getChildren() { - return $this->getSousCategories(); - } - - - public function getIdZone() { if (!$this->hasZone()) return 0; diff --git a/library/Class/UserGroupCategorie.php b/library/Class/UserGroupCategorie.php index b1cccf99f0b..76f599b89fa 100644 --- a/library/Class/UserGroupCategorie.php +++ b/library/Class/UserGroupCategorie.php @@ -51,6 +51,7 @@ class UserGroupCategorieLoader extends Storm_Model_Loader{ class Class_UserGroupCategorie extends Storm_Model_Abstract { use Trait_TreeViewableCategorie, Trait_Translator, Trait_TreeNode; + protected $_table_name = 'user_group_categorie', $_loader_class = 'UserGroupCategorieLoader', @@ -72,32 +73,11 @@ class Class_UserGroupCategorie extends Storm_Model_Abstract { $_default_attribute_values = ['parent_id' => 0]; - /** [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][voir Trait_TreeNode]] */ - public function getParent() { - return $this->getParentCategorie(); - } - - - /** - * cf [[file:~/public_html/afi-opac3/library/Trait/TreeNode.php::trait%20Trait_TreeNode%20{][Trait_TreeNode]] - */ - public function getChildren() { - return $this->getSousCategories(); - } - - /** - * @return array - */ public function getItems() { return $this->getUserGroups(); } - public function getSousCategories() { - return parent::_get('sous_categories'); - } - - public function getIdCatMere() { return $this->getParentId(); } diff --git a/library/Trait/Tree.php b/library/Trait/Tree.php new file mode 100644 index 00000000000..93aa996a77a --- /dev/null +++ b/library/Trait/Tree.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +trait Trait_Tree { + abstract public function getParent(); + abstract public function getChildren(); +} \ No newline at end of file diff --git a/library/Trait/TreeNode.php b/library/Trait/TreeNode.php index dd7e4fa7f9a..177f5663f51 100644 --- a/library/Trait/TreeNode.php +++ b/library/Trait/TreeNode.php @@ -20,6 +20,8 @@ */ trait Trait_TreeNode { + use Trait_Tree; + public static $PATH_SEPARATOR = '/'; protected $_path_cache = []; @@ -87,10 +89,12 @@ trait Trait_TreeNode { } - abstract public function getParent(); - - abstract public function getChildren(); + public function getLeaves() { + ; + } -} -?> \ No newline at end of file + public function getNodes() { + ; + } +} \ No newline at end of file diff --git a/library/Trait/TreeViewableCategorie.php b/library/Trait/TreeViewableCategorie.php index 16eb30d7025..56dd3940c38 100644 --- a/library/Trait/TreeViewableCategorie.php +++ b/library/Trait/TreeViewableCategorie.php @@ -16,10 +16,12 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ trait Trait_TreeViewableCategorie { + use Trait_Tree; + /** * @return bool */ @@ -75,6 +77,14 @@ trait Trait_TreeViewableCategorie { '"items": ['.implode(",", $json_items).']'. '}'; } -} -?> \ No newline at end of file + + public function getParent() { + return $this->getParentCategorie(); + } + + + public function getChildren() { + return $this->getSousCategories(); + } +} \ No newline at end of file diff --git a/library/Trait/TreeViewableItem.php b/library/Trait/TreeViewableItem.php index 0f6ba15cb36..eb01606fe2c 100644 --- a/library/Trait/TreeViewableItem.php +++ b/library/Trait/TreeViewableItem.php @@ -20,6 +20,8 @@ */ trait Trait_TreeViewableItem { + use Trait_Tree; + public function getBib() { return $this->getCategorie() ? $this->getCategorie()->getBib() @@ -61,6 +63,14 @@ trait Trait_TreeViewableItem { "label" => htmlspecialchars($this->getLibelle())]); } -} -?> \ No newline at end of file + + public function getParent() { + return $this->getCategorie(); + } + + + public function getChildren() { + return []; + } +} \ No newline at end of file -- GitLab