Commit 1f36e980 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(management) Add a ListingEntry type

It allows to carry information like type, dn, row number along with the
 attributes array for an entry
parent 2ba71e7e
......@@ -326,23 +326,23 @@ class management
return '<div id="pulldown">'.$result.'</ul></li></ul></div>'."\n";
}
function renderActionColumn($pid, $row, $dn, $type, array $entry)
function renderActionColumn(ListingEntry $entry)
{
// Go thru all actions
$result = '';
foreach ($this->actions as $action) {
$result .= $action->renderColumnIcons($pid, $row, $dn, $type, $entry);
$result .= $action->renderColumnIcons($entry);
}
return $result;
}
function getActionRowClasses($pid, $row, $dn, $type, array $entry)
function getActionRowClasses(ListingEntry $entry)
{
$classes = array();
foreach ($this->actions as $action) {
// TODO optimize
$classes = array_merge($classes, $action->getRowClasses($pid, $row, $dn, $type, $entry));
$classes = array_merge($classes, $action->getRowClasses($entry));
}
return $classes;
......@@ -624,7 +624,8 @@ class management
// Add locks
$objects = array();
foreach ($this->dns as $dn) {
$type = $this->listing->getType($dn);
$entry = $this->listing->getEntry($dn);
$type = $entry->type;
if (preg_match('/^template_/', $type) && !static::$skipTemplates) {
$type = preg_replace('/^template_/', '', $type);
$info = objects::infos($type);
......@@ -632,7 +633,6 @@ class management
} else {
$info = objects::infos($type);
}
$entry = $this->listing->getEntry($dn);
$objects[] = array(
'name' => $entry[$info['nameAttr']],
'dn' => $dn,
......
......@@ -124,19 +124,19 @@ class Action
.'</li>'."\n";
}
function getRowClasses($pid, $row, $dn, $type, array $entry)
function getRowClasses(ListingEntry $entry)
{
return array();
}
function renderColumnIcons($pid, $row, $dn, $type, array $entry)
function renderColumnIcons(ListingEntry $entry)
{
if (!$this->inline) {
return '';
}
// Skip the entry completely if there's no permission to execute it
if (!$this->hasPermission($dn, $type)) {
if (!$this->hasPermission($entry->dn, $entry->type)) {
return '<img src="images/empty.png" alt=" " class="center optional"/>';
}
......@@ -145,7 +145,7 @@ class Action
// Render
return '<input class="center" type="image" src="'.htmlentities($this->icon, ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label.'" alt="'.$this->label.'" name="listing_'.$this->name.'_'.$row.'"/>';
' title="'.$this->label.'" alt="'.$this->label.'" name="listing_'.$this->name.'_'.$entry->row.'"/>';
}
function hasPermission($dn, $type)
......@@ -231,7 +231,7 @@ class ActionSubMenu extends Action
return $result.'</li></ul>'."\n";
}
function renderColumnIcons($pid, $row, $dn, $type, array $entry)
function renderColumnIcons(ListingEntry $entry)
{
}
}
......
......@@ -72,12 +72,12 @@ class StringColumn
}
}
function getRowClasses($pid, $row, $dn, $type, array $entry)
function getRowClasses(ListingEntry $entry)
{
return array();
}
function renderCell($pid, $row, $dn, $type, array $entry)
function renderCell(ListingEntry $entry)
{
if (isset($this->attribute) && isset($entry[$this->attribute])) {
return htmlentities($entry[$this->attribute], ENT_COMPAT, 'UTF-8');
......@@ -153,10 +153,10 @@ class StringColumn
class LinkColumn extends StringColumn
{
function renderCell($pid, $row, $dn, $type, array $entry)
function renderCell(ListingEntry $entry)
{
if (isset($entry[$this->attribute])) {
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$pid.'&amp;act=listing_edit_'.$row.'" title="'.$dn.'">'.htmlentities($entry[$this->attribute], ENT_COMPAT, 'UTF-8').'</a>';
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.htmlentities($entry[$this->attribute], ENT_COMPAT, 'UTF-8').'</a>';
} else {
return '&nbsp;';
}
......@@ -170,11 +170,11 @@ class ObjectTypeColumn extends StringColumn
return FALSE;
}
function renderCell($pid, $row, $dn, $type, array $entry)
function renderCell(ListingEntry $entry)
{
if ($type) {
$infos = objects::infos($type);
return '<img class="center" title="'.$dn.'" src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" alt="'.$infos['name'].'"/>';
if ($entry->type) {
$infos = objects::infos($entry->type);
return '<img class="center" title="'.$entry->dn.'" src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" alt="'.$infos['name'].'"/>';
} else {
return '&nbsp;';
}
......@@ -188,14 +188,14 @@ class ActionsColumn extends StringColumn
return FALSE;
}
function getRowClasses($pid, $row, $dn, $type, array $entry)
function getRowClasses(ListingEntry $entry)
{
return $this->parent->parent->getActionRowClasses($pid, $row, $dn, $type, $entry);
return $this->parent->parent->getActionRowClasses($entry);
}
function renderCell($pid, $row, $dn, $type, array $entry)
function renderCell(ListingEntry $entry)
{
return $this->parent->parent->renderActionColumn($pid, $row, $dn, $type, $entry);
return $this->parent->parent->renderActionColumn($entry);
}
}
......@@ -211,16 +211,16 @@ class PropertiesColumn extends StringColumn
$attrs['objectClass'] = '*';
}
function renderCell($pid, $row, $dn, $type, array $entry)
function renderCell(ListingEntry $entry)
{
global $config;
$infos = objects::infos($type);
$infos = objects::infos($entry->type);
static $tabs = array();
if (empty($tabs[$type])) {
$tabs[$type] = array();
if (empty($tabs[$entry->type])) {
$tabs[$entry->type] = array();
foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) {
if ($plug['CLASS'] == $infos['mainTab']) {
continue;
......@@ -228,7 +228,7 @@ class PropertiesColumn extends StringColumn
if (class_available($plug['CLASS'])) {
$name = $plug['CLASS'];
$tabs[$type][$name] = new $name('new');
$tabs[$entry->type][$name] = new $name('new');
}
}
}
......@@ -237,18 +237,18 @@ class PropertiesColumn extends StringColumn
$pInfos = pluglist::pluginInfos($infos['mainTab']);
$result = '<input class="center" type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$infos['mainTab'].'_'.$row.'"/>';
'name="listing_edit_tab_'.$infos['mainTab'].'_'.$entry->row.'"/>';
if (!empty($entry)) {
//~ if (in_array_ics ('fdTemplate', $attrs['objectClass'])) {
//~ $attrs = templateHandling::fieldsFromLDAP($attrs);
//~ }
foreach ($tabs[$type] as $class => $tab) {
foreach ($tabs[$entry->type] as $class => $tab) {
if ($tab->is_this_account($entry)) {
$pInfos = pluglist::pluginInfos($class);
if (isset($pInfos['plSmallIcon'])) {
$result .= '<input class="center" type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$class.'_'.$row.'"/>';
'name="listing_edit_tab_'.$class.'_'.$entry->row.'"/>';
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $pInfos['plShortName']." ($class)", 'No icon for');
}
......
......@@ -114,6 +114,48 @@ class entrySortIterator implements Iterator {
}
}
class ListingEntry implements ArrayAccess
{
public $dn;
public $row;
public $type;
private $attrs;
protected $listing;
public function __construct(managementListing $listing, $type, $dn, array $attrs, $row = NULL) {
$this->listing = $listing;
$this->type = $type;
$this->dn = $dn;
$this->attrs = $attrs;
$this->row = $row;
}
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->attrs[$offset] = $value;
}
}
public function offsetExists($offset) {
return isset($this->attrs[$offset]);
}
public function offsetUnset($offset) {
unset($this->attrs[$offset]);
}
public function offsetGet($offset) {
return (isset($this->attrs[$offset]) ? $this->attrs[$offset] : NULL);
}
public function getPid()
{
return $this->listing->pid;
}
}
/*!
* \brief This class handles the entries list for a management instance
*/
......@@ -121,7 +163,6 @@ class managementListing
{
protected $entries = array();
protected $entriesIndex = array();
protected $entriesTypes = array();
//~ var $departments = array();
//~ var $departmentBrowser = FALSE;
//~ var $departmentRootVisible = FALSE;
......@@ -142,7 +183,7 @@ class managementListing
//~ protected $colprops = array();
//~ protected $filters = array();
//~ protected $filter = NULL;
protected $pid;
public $pid;
//~ protected $departmentTypes = array();
//~ var $objectTypes = array();
protected $objectTypeCount = array();
......@@ -194,10 +235,8 @@ class managementListing
// Register build in filters
//~ $this->registerElementFilter("departmentType", "listing::filterDepartmentType");
//~ $this->registerElementFilter("departmentLink", "listing::filterDepartmentLink");
//~ $this->registerElementFilter("objectType", "listing::filterObjectType");
//~ $this->registerElementFilter("link", "listing::filterLink");
//~ $this->registerElementFilter("nameLink", "listing::filterNameLink");
//~ $this->registerElementFilter("actions", "listing::filterActions");
// Load exporters
//~ foreach (array_keys($class_mapping) as $class) {
......@@ -216,9 +255,9 @@ class managementListing
new ObjectTypeColumn(),
new LinkColumn('sn', 'Last name'),
new LinkColumn('givenName', 'First name'),
new StringColumn('uid', 'Login'),
new PropertiesColumn(NULL, 'Properties'),
new ActionsColumn(NULL, 'Actions'),
new StringColumn('uid', 'Login'),
new PropertiesColumn(NULL, 'Properties'),
new ActionsColumn(NULL, 'Actions'),
);
foreach ($this->columns as $column) {
......@@ -387,9 +426,9 @@ class managementListing
}
foreach ($this->columns as $index => $column) {
$renderedCell = $column->renderCell($this->pid, $row, $dn, $this->entriesTypes[$dn], $entry);
$renderedCell = $column->renderCell($entry);
$trow .= '<td '.$column->getHtmlCellProps().'>'.$renderedCell.'</td>'."\n";
$rowclasses = array_merge($rowclasses, $column->getRowClasses($this->pid, $row, $dn, $this->entriesTypes[$dn], $entry));
$rowclasses = array_merge($rowclasses, $column->getRowClasses($entry));
}
// Save rendered entry
......@@ -557,7 +596,7 @@ class managementListing
}
$this->objectTypeCount = array();
$this->entries = array();
$this->entriesTypes = array();
$row = 0;
foreach ($this->parent->objectTypes as $type) {
// TODO: How do we handle collisions?
$infos = objects::infos($type);
......@@ -575,8 +614,9 @@ class managementListing
$entries = objects::ls($type, $attrsAsked, $base, '', TRUE, 'one');
$this->objectTypeCount[$type] = count($entries);
$this->entries = array_merge($this->entries, $entries);
$this->entriesTypes = array_merge($this->entriesTypes, array_fill_keys(array_keys($this->entries), $type));
foreach ($entries as $dn => $entry) {
$this->entries[$dn] = new ListingEntry($this, $type, $dn, $entry, $row++);
}
}
/* Store the order of the entries to access them by index later */
$this->entriesIndex = array_keys($this->entries);
......@@ -1400,8 +1440,8 @@ class managementListing
*/
function getType($dn)
{
if (isset($this->entriesTypes[$dn])) {
return $this->entriesTypes[$dn];
if (isset($this->entries[$dn])) {
return $this->entries[$dn]->type;
}
return NULL;
}
......
......@@ -33,7 +33,7 @@ class LockAction extends Action
$targets, $callable, $acl, $inmenu, $inline);
}
function isLocked(array $entry)
function isLocked(ListingEntry $entry)
{
if (isset($entry['userPassword']) && preg_match('/^\{[^\}]/', $entry['userPassword'])) {
if (preg_match('/^[^\}]*+\}!/', $entry['userPassword'])) {
......@@ -65,7 +65,7 @@ class LockAction extends Action
.'</li>'."\n";
}
function getRowClasses($pid, $row, $dn, $type, array $entry)
function getRowClasses(ListingEntry $entry)
{
$lockStatus = $this->isLocked($entry);
if ($lockStatus === TRUE) {
......@@ -75,14 +75,14 @@ class LockAction extends Action
}
}
function renderColumnIcons($pid, $row, $dn, $type, array $entry)
function renderColumnIcons(ListingEntry $entry)
{
if (!$this->inline) {
return '';
}
// Skip the entry completely if there's no permission to execute it
if (!$this->hasPermission($dn, $type)) {
if (!$this->hasPermission($entry->dn, $entry->type)) {
return '<img src="images/empty.png" alt=" " class="center optional"/>';
}
......@@ -92,10 +92,10 @@ class LockAction extends Action
} elseif ($lockStatus) {
// Render
return '<input class="center" type="image" src="'.htmlentities($this->icon['lock'], ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label['unlock'].'" alt="'.$this->label['unlock'].'" name="listing_'.$this->name.'_unlock_'.$row.'"/>';
' title="'.$this->label['unlock'].'" alt="'.$this->label['unlock'].'" name="listing_'.$this->name.'_unlock_'.$entry->row.'"/>';
} else {
return '<input class="center" type="image" src="'.htmlentities($this->icon['unlock'], ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label['lock'].'" alt="'.$this->label['lock'].'" name="listing_'.$this->name.'_lock_'.$row.'"/>';
' title="'.$this->label['lock'].'" alt="'.$this->label['lock'].'" name="listing_'.$this->name.'_lock_'.$entry->row.'"/>';
}
}
}
......@@ -135,13 +135,6 @@ class userManagement extends management
array('userPassword:rw'), TRUE, TRUE
)
);
//~ $this->registerAction(
//~ new LockAction(
//~ 'unlockUsers', _('Unlock'), 'geticon.php?context=status&icon=object-unlocked&size=16',
//~ '+', 'lockUsers',
//~ array('userPassword:rw'), TRUE, TRUE, FALSE
//~ )
//~ );
}
function configureFilter ()
......
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