From ef4aa1aaf6d8371a7cd121690055f57593aa9f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Thu, 22 Feb 2018 11:15:06 +0100 Subject: [PATCH] :sparkles: feat(management) Reorganize column classes --- .../management/class_managementListing.inc | 2 +- .../columns/class_ActionsColumn.inc | 40 ++++++ .../class_Column.inc} | 122 +----------------- .../management/columns/class_LinkColumn.inc | 38 ++++++ .../columns/class_ObjectTypeColumn.inc | 43 ++++++ .../columns/class_PropertiesColumn.inc | 87 +++++++++++++ 6 files changed, 210 insertions(+), 122 deletions(-) create mode 100644 include/management/columns/class_ActionsColumn.inc rename include/management/{class_managementColumn.inc => columns/class_Column.inc} (51%) create mode 100644 include/management/columns/class_LinkColumn.inc create mode 100644 include/management/columns/class_ObjectTypeColumn.inc create mode 100644 include/management/columns/class_PropertiesColumn.inc diff --git a/include/management/class_managementListing.inc b/include/management/class_managementListing.inc index 7c033209c..bf629ca30 100644 --- a/include/management/class_managementListing.inc +++ b/include/management/class_managementListing.inc @@ -207,7 +207,7 @@ class managementListing new ObjectTypeColumn(), new LinkColumn('sn', 'Last name'), new LinkColumn('givenName', 'First name'), - new StringColumn('uid', 'Login'), + new Column('uid', 'Login'), new PropertiesColumn(NULL, 'Properties'), new ActionsColumn(NULL, 'Actions'), ); diff --git a/include/management/columns/class_ActionsColumn.inc b/include/management/columns/class_ActionsColumn.inc new file mode 100644 index 000000000..4ea91a979 --- /dev/null +++ b/include/management/columns/class_ActionsColumn.inc @@ -0,0 +1,40 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2017-2018 FusionDirectory + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/*! + * \brief Column showing the actions available on the object + */ +class ActionsColumn extends Column +{ + function isSortable() + { + return FALSE; + } + + function getRowClasses(ListingEntry $entry) + { + return $this->parent->parent->getActionRowClasses($entry); + } + + function renderCell(ListingEntry $entry) + { + return $this->parent->parent->renderActionColumn($entry); + } +} diff --git a/include/management/class_managementColumn.inc b/include/management/columns/class_Column.inc similarity index 51% rename from include/management/class_managementColumn.inc rename to include/management/columns/class_Column.inc index 2fdb54b66..980e1c6f9 100644 --- a/include/management/class_managementColumn.inc +++ b/include/management/columns/class_Column.inc @@ -21,7 +21,7 @@ /*! * \brief Column base class */ -class StringColumn +class Column { protected $attribute; protected $label; @@ -161,123 +161,3 @@ class StringColumn } } } - -class LinkColumn extends StringColumn -{ - function renderCell(ListingEntry $entry) - { - $attribute = $this->attribute; - if (isset($this->templateAttribute) && $entry->isTemplate()) { - $attribute = $this->templateAttribute; - } - if (isset($entry[$attribute])) { - return '<a href="?plug='.$_GET['plug'].'&PID='.$entry->getPid().'&act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.htmlentities($entry[$attribute], ENT_COMPAT, 'UTF-8').'</a>'; - } else { - return ' '; - } - } -} - -class ObjectTypeColumn extends StringColumn -{ - function isSortable() - { - return FALSE; - } - - function renderCell(ListingEntry $entry) - { - if ($entry->isTemplate()) { - $infos = objects::infos($entry->getTemplatedType()); - return '<img title="'.$entry->dn.'" src="'.htmlentities('geticon.php?context=devices&icon=template&size=16', ENT_COMPAT, 'UTF-8').'" alt="'.sprintf(_('%s template'), $infos['name']).'"/>'; - } elseif ($entry->type) { - $infos = objects::infos($entry->type); - return '<img title="'.$entry->dn.'" src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" alt="'.$infos['name'].'"/>'; - } else { - return ' '; - } - } -} - -class ActionsColumn extends StringColumn -{ - function isSortable() - { - return FALSE; - } - - function getRowClasses(ListingEntry $entry) - { - return $this->parent->parent->getActionRowClasses($entry); - } - - function renderCell(ListingEntry $entry) - { - return $this->parent->parent->renderActionColumn($entry); - } -} - -class PropertiesColumn extends StringColumn -{ - function isSortable() - { - return FALSE; - } - - function fillNeededAttributes(array &$attrs) - { - $attrs['objectClass'] = '*'; - } - - function renderCell(ListingEntry $entry) - { - global $config; - - $infos = objects::infos($entry->getTemplatedType()); - - static $tabs = array(); - - if (empty($tabs[$entry->type])) { - $tabs[$entry->type] = array(); - foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) { - if ($plug['CLASS'] == $infos['mainTab']) { - continue; - } - if (class_available($plug['CLASS'])) { - $name = $plug['CLASS']; - - $tabs[$entry->type][$name] = new $name('new'); - } - } - } - - /* Main tab is always there */ - $pInfos = pluglist::pluginInfos($infos['mainTab']); - $result = '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '. - 'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '. - 'name="listing_edit_tab_'.$infos['mainTab'].'_'.$entry->row.'"/>'; - if (!empty($entry)) { - if ($entry->isTemplate()) { - $attrs = $entry->getTemplatedFields(); - } else { - $attrs = $entry; - } - foreach ($tabs[$entry->type] as $class => $tab) { - if ($tab->is_this_account($attrs)) { - $pInfos = pluglist::pluginInfos($class); - if (isset($pInfos['plSmallIcon'])) { - $result .= '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '. - 'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '. - 'name="listing_edit_tab_'.$class.'_'.$entry->row.'"/>'; - } else { - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $pInfos['plShortName']." ($class)", 'No icon for'); - } - } else { - $result .= '<img src="images/empty.png" alt="" class="optional '.$class.'"/>'; - } - } - } - - return $result; - } -} diff --git a/include/management/columns/class_LinkColumn.inc b/include/management/columns/class_LinkColumn.inc new file mode 100644 index 000000000..185e836de --- /dev/null +++ b/include/management/columns/class_LinkColumn.inc @@ -0,0 +1,38 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2017-2018 FusionDirectory + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/*! + * \brief Column rendering a link to edit the object + */ +class LinkColumn extends Column +{ + function renderCell(ListingEntry $entry) + { + $attribute = $this->attribute; + if (isset($this->templateAttribute) && $entry->isTemplate()) { + $attribute = $this->templateAttribute; + } + if (isset($entry[$attribute])) { + return '<a href="?plug='.$_GET['plug'].'&PID='.$entry->getPid().'&act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.htmlentities($entry[$attribute], ENT_COMPAT, 'UTF-8').'</a>'; + } else { + return ' '; + } + } +} diff --git a/include/management/columns/class_ObjectTypeColumn.inc b/include/management/columns/class_ObjectTypeColumn.inc new file mode 100644 index 000000000..8e3038745 --- /dev/null +++ b/include/management/columns/class_ObjectTypeColumn.inc @@ -0,0 +1,43 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2017-2018 FusionDirectory + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/*! + * \brief Column showing the icon of the objectType + */ +class ObjectTypeColumn extends Column +{ + function isSortable() + { + return FALSE; + } + + function renderCell(ListingEntry $entry) + { + if ($entry->isTemplate()) { + $infos = objects::infos($entry->getTemplatedType()); + return '<img title="'.$entry->dn.'" src="'.htmlentities('geticon.php?context=devices&icon=template&size=16', ENT_COMPAT, 'UTF-8').'" alt="'.sprintf(_('%s template'), $infos['name']).'"/>'; + } elseif ($entry->type) { + $infos = objects::infos($entry->type); + return '<img title="'.$entry->dn.'" src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" alt="'.$infos['name'].'"/>'; + } else { + return ' '; + } + } +} diff --git a/include/management/columns/class_PropertiesColumn.inc b/include/management/columns/class_PropertiesColumn.inc new file mode 100644 index 000000000..dd202df06 --- /dev/null +++ b/include/management/columns/class_PropertiesColumn.inc @@ -0,0 +1,87 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2017-2018 FusionDirectory + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/*! + * \brief Column showing the activated tabs of the object + */ +class PropertiesColumn extends Column +{ + function isSortable() + { + return FALSE; + } + + function fillNeededAttributes(array &$attrs) + { + $attrs['objectClass'] = '*'; + } + + function renderCell(ListingEntry $entry) + { + global $config; + + $infos = objects::infos($entry->getTemplatedType()); + + static $tabs = array(); + + if (empty($tabs[$entry->type])) { + $tabs[$entry->type] = array(); + foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) { + if ($plug['CLASS'] == $infos['mainTab']) { + continue; + } + if (class_available($plug['CLASS'])) { + $name = $plug['CLASS']; + + $tabs[$entry->type][$name] = new $name('new'); + } + } + } + + /* Main tab is always there */ + $pInfos = pluglist::pluginInfos($infos['mainTab']); + $result = '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '. + 'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '. + 'name="listing_edit_tab_'.$infos['mainTab'].'_'.$entry->row.'"/>'; + if (!empty($entry)) { + if ($entry->isTemplate()) { + $attrs = $entry->getTemplatedFields(); + } else { + $attrs = $entry; + } + foreach ($tabs[$entry->type] as $class => $tab) { + if ($tab->is_this_account($attrs)) { + $pInfos = pluglist::pluginInfos($class); + if (isset($pInfos['plSmallIcon'])) { + $result .= '<input type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '. + 'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '. + 'name="listing_edit_tab_'.$class.'_'.$entry->row.'"/>'; + } else { + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $pInfos['plShortName']." ($class)", 'No icon for'); + } + } else { + $result .= '<img src="images/empty.png" alt="" class="optional '.$class.'"/>'; + } + } + } + + return $result; + } +} -- GitLab