Commit 72e5221d authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚜 fix(core) Migrate PhoneNumberAttribute to selectManagement

issue #5965
parent 9f4cd8c9
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2016-2017 FusionDirectory
Copyright (C) 2016-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
......@@ -21,89 +22,22 @@
/*!
* \brief Phone number selection
*/
class phoneSelect extends simpleSelectManagement
class phoneSelect extends selectManagement
{
protected $multiSelect = FALSE;
protected $autoFilterAttributes = ['dn','cn','ipHostNumber','macAddress','telephoneNumber'];
protected $objectTypes = ['phone'];
function parseXML ($file)
{
$data = parent::parseXML($file);
/* Add column for phone number */
$data['list']['table']['layout'] .= '|';
$columns = [
[
'label' => _('Number'),
'sortAttribute' => 'telephoneNumber',
'sortType' => 'string',
'value' => '%{filter:selectLink(pid,row,dn,telephoneNumber)}',
'export' => 'true',
],
];
array_splice($data['list']['table']['column'], 2, 0, $columns);
return $data;
}
function configureFilter ()
{
parent::configureFilter();
/* Only display entries with a phone number */
$this->filter->query[0]['filter'] = '(&(telephoneNumber=*)'.$this->filter->query[0]['filter'].')';
}
}
/*!
* \brief Mobile phone number selection
*/
class mobilePhoneSelect extends phoneSelect
{
protected $objectTypes = ['mobilePhone'];
}
/*!
* \brief Phone number selection allowing both Phone and Mobile phone objects
*/
class anyPhoneSelect extends phoneSelect
{
protected $objectTypes = ['phone','mobilePhone'];
/* Default columns */
public static $columns = [
['ObjectTypeColumn', []],
['LinkColumn', ['attributes' => 'nameAttr', 'label' => 'Name']],
['LinkColumn', ['attributes' => 'telephoneNumber', 'label' => 'Number']],
];
}
/*!
* \brief Phone number selection dialog
*/
class phoneSelectDialog extends GenericDialog
class phoneSelectDialog extends GenericSingleSelectManagementDialog
{
function __construct ($simplePlugin, $attribute, $type)
{
$this->attribute = $attribute;
switch ($type) {
case 'phone':
$this->dialog = new phoneSelect();
break;
case 'mobile':
$this->dialog = new mobilePhoneSelect();
break;
case 'any':
$this->dialog = new anyPhoneSelect();
break;
default:
trigger_error('Unknown phone select type '.$type);
break;
}
}
function handle_finish ()
{
$result = $this->dialog->detectPostActions();
if (isset($result['targets']) && count($result['targets'])) {
$headpage = $this->dialog->getHeadpage();
$dn = $result['targets'][0];
$attrs = $headpage->getEntry($dn);
$this->attribute->handleDialogResult($dn, $attrs);
}
return FALSE;
}
protected $dialogClass = 'phoneSelect';
}
/*! \brief This class allow to handle easily an LDAP attribute that contains a phone number
......@@ -124,11 +58,40 @@ class PhoneNumberAttribute extends StringAttribute
class PhoneNumberButtonAttribute extends PhoneNumberAttribute
{
protected $type;
protected $dialogClass = 'phoneSelectDialog';
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = '', $type = 'phone', $acl = '')
{
parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->dialogClass = 'phoneSelectDialog';
switch ($type) {
case 'phone':
$objectTypes = ['phone'];
break;
case 'mobile':
$objectTypes = ['mobilePhone'];
break;
case 'any':
$objectTypes = ['phone','mobilePhone'];
break;
default:
throw new FusionDirectoryException('Invalid type "'.$type.'" for PhoneNumberButtonAttribute');
break;
}
$this->selectManagementParameters = [
$objectTypes,
FALSE,
[
'objectClass' => '*',
'dn' => 'raw',
'cn' => '*',
'ipHostNumber' => '*',
'macAddress' => '*',
'telephoneNumber' => '*',
]
];
if (class_available('phoneGeneric')) {
$this->type = $type;
} else {
......@@ -171,7 +134,7 @@ class PhoneNumberButtonAttribute extends PhoneNumberAttribute
if (!$this->disabled && $this->isVisible()) {
foreach (array_keys($_POST) as $name) {
if (preg_match('/^'.$id.'_edit_/', $name)) {
$this->plugin->openDialog(new $this->dialogClass($this->plugin, $this, $this->type));
$this->plugin->openDialog(new $this->dialogClass($this->plugin, $this));
break;
}
}
......
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