Commit 4fa6c24c authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(management) Add DateFilterElement and LdapGeneralizedTimeColumn

Both will be used in auditManagement

issue #5135
parent 17b902bd
<fieldset><legend>{$NAME}</legend>
<label for="nt_{$attribute}" title="{t 1=$NAME}Minimum date for %1{/t}">
{t}Newer than{/t}
<input type="date" id="nt_{$attribute}" name="nt_{$attribute}" value="{$nt_value}"/>
</label>
<label for="ot_{$attribute}" title="{t 1=$NAME}Maximum date for %1{/t}">
{t}Older than{/t}
<input type="date" id="ot_{$attribute}" name="ot_{$attribute}" value="{$ot_value}"/>
</label>
</fieldset>
<?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 Filter on member types
*/
class DateFilterElement extends FilterElement
{
protected $attribute;
protected $label;
protected $min;
protected $max;
protected $types;
public function __construct(managementFilter $parent, $attribute, $label, $types = array())
{
global $config;
parent::__construct($parent);
$this->attribute = $attribute;
$this->label = $label;
$this->types = $types;
}
public function update()
{
if (!empty($_POST['nt_'.$this->attribute])) {
$this->min = $_POST['nt_'.$this->attribute];
} else {
$this->min = '';
}
if (!empty($_POST['ot_'.$this->attribute])) {
$this->max = $_POST['ot_'.$this->attribute];
} else {
$this->max = '';
}
}
public function render()
{
$smarty = get_smarty();
$smarty->assign('NAME', $this->label);
$smarty->assign('attribute', $this->attribute);
$smarty->assign('nt_value', $this->min);
$smarty->assign('ot_value', $this->max);
return $smarty->fetch(get_template_path('management/filter-element-date.tpl'));
}
public function getFilters($type, array &$filters)
{
if (!empty($this->types) && !in_array_ics($type, $this->types)) {
return FALSE;
}
if (!empty($this->min)) {
$filters[] = '('.$this->attribute.'>='.LdapGeneralizedTime::toString(new DateTime($this->min)).')';
}
if (!empty($this->max)) {
$filters[] = '('.$this->attribute.'<='.LdapGeneralizedTime::toString(new DateTime($this->max)).')';
}
return FALSE;
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
Copyright (C) 2017-2019 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
......@@ -45,77 +46,3 @@ class FilterElement
return FALSE;
}
}
class TabFilterElement extends FilterElement
{
protected $tabs;
public function __construct(managementFilter $parent)
{
global $config;
parent::__construct($parent);
$this->tabs = array();
foreach ($this->parent->parent->objectTypes as $type) {
$infos = objects::infos($type);
foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) {
$class = $plug['CLASS'];
if ($class == $infos['mainTab']) {
continue;
}
if (isset($this->tabs[$class])) {
continue;
}
if (class_available($class)) {
$classInfos = pluglist::pluginInfos($class);
if (isset($classInfos['plFilterObject'])) {
$this->tabs[$class] = array(
'filter' => $classInfos['plFilterObject'],
'infos' => $classInfos,
'checked' => FALSE,
);
}
}
}
}
}
public function update()
{
foreach ($this->tabs as $class => &$tab) {
$tab['checked'] = isset($_POST['filter_tab_'.$class]);
}
unset($tab);
}
public function render()
{
if (empty($this->tabs)) {
return '';
}
$inputs = array();
foreach ($this->tabs as $class => $tab) {
$inputs['filter_tab_'.$class] = array(
'name' => $tab['infos']['plShortName'],
'desc' => $tab['infos']['plShortName'].' '.$tab['filter'],
'icon' => (isset($tab['infos']['plSmallIcon']) ? $tab['infos']['plSmallIcon'] : NULL),
'checked' => $tab['checked'],
);
}
$smarty = get_smarty();
$smarty->assign('NAME', _('Tabs'));
$smarty->assign('INPUTS', $inputs);
return $smarty->fetch(get_template_path('management/filter-element.tpl'));
}
public function getFilters($type, array &$filters)
{
foreach ($this->tabs as $tab) {
if ($tab['checked']) {
$filters[] = $tab['filter'];
}
}
return FALSE;
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2019 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.
*/
class TabFilterElement extends FilterElement
{
protected $tabs;
public function __construct(managementFilter $parent)
{
global $config;
parent::__construct($parent);
$this->tabs = array();
foreach ($this->parent->parent->objectTypes as $type) {
$infos = objects::infos($type);
foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) {
$class = $plug['CLASS'];
if ($class == $infos['mainTab']) {
continue;
}
if (isset($this->tabs[$class])) {
continue;
}
if (class_available($class)) {
$classInfos = pluglist::pluginInfos($class);
if (isset($classInfos['plFilterObject'])) {
$this->tabs[$class] = array(
'filter' => $classInfos['plFilterObject'],
'infos' => $classInfos,
'checked' => FALSE,
);
}
}
}
}
}
public function update()
{
foreach ($this->tabs as $class => &$tab) {
$tab['checked'] = isset($_POST['filter_tab_'.$class]);
}
unset($tab);
}
public function render()
{
if (empty($this->tabs)) {
return '';
}
$inputs = array();
foreach ($this->tabs as $class => $tab) {
$inputs['filter_tab_'.$class] = array(
'name' => $tab['infos']['plShortName'],
'desc' => $tab['infos']['plShortName'].' '.$tab['filter'],
'icon' => (isset($tab['infos']['plSmallIcon']) ? $tab['infos']['plSmallIcon'] : NULL),
'checked' => $tab['checked'],
);
}
$smarty = get_smarty();
$smarty->assign('NAME', _('Tabs'));
$smarty->assign('INPUTS', $inputs);
return $smarty->fetch(get_template_path('management/filter-element.tpl'));
}
public function getFilters($type, array &$filters)
{
foreach ($this->tabs as $tab) {
if ($tab['checked']) {
$filters[] = $tab['filter'];
}
}
return FALSE;
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2018-2019 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 LdapGeneralizedTime attributes
*/
class LdapGeneralizedTimeColumn extends LinkColumn
{
protected $type = 'string';
function renderCell(ListingEntry $entry)
{
$value = $this->getAttributeValue($entry);
if ($value != '') {
$dateObject = LdapGeneralizedTime::fromString($value);
if (is_object($dateObject)) {
return $this->renderLink($entry, $dateObject->format('Y-m-d, H:i:s'));
}
}
return '&nbsp;';
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment