Commit 6663a8c9 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(management) Add sort by properties feature

issue #5135
parent 69d6b88b
......@@ -26,6 +26,9 @@ class ListingEntry implements ArrayAccess
private $attrs;
protected $listing;
/* Cache where columns may store stuff */
public $cache = array();
public function __construct(managementListing $listing, $type, $dn, array $attrs, $row = NULL)
{
$this->listing = $listing;
......
......@@ -130,7 +130,7 @@ class Column
}
}
function compare($ao, $bo)
function compare(ListingEntry $ao, ListingEntry $bo)
{
if ($this->attribute == 'sort-attribute') {
// Override sort attribute from data if needed
......
......@@ -47,11 +47,6 @@ class PropertiesColumn extends Column
}
}
function isSortable()
{
return FALSE;
}
function fillNeededAttributes(array &$attrs)
{
foreach ($this->tabs as $classes) {
......@@ -63,15 +58,68 @@ class PropertiesColumn extends Column
function renderCell(ListingEntry $entry)
{
global $config;
$tabs = $this->computeIcons($entry);
  • Rename "$tabs" which has the same name as the field declared at line 26. 📘

Please register or sign in to reply
$result = '';
foreach ($tabs as $tab) {
if (empty($tab['icon'])) {
$result .= '<img src="images/empty.png" alt="" class="optional '.$tab['tab'].'"/>';
} else {
$result .= '<input type="image" src="'.htmlentities($tab['icon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$tab['title'].'" title="'.$tab['title'].'" '.
'name="listing_edit_tab_'.$tab['tab'].'_'.$entry->row.'"/>';
}
}
return $result;
}
function compare(ListingEntry $ao, ListingEntry $bo)
{
if ($ao->getTemplatedType() != $bo->getTemplatedType()) {
return strcmp($ao->getTemplatedType(), $bo->getTemplatedType());
}
// Extract values from ao and bo
$a = $this->computeSortString($ao);
$b = $this->computeSortString($bo);
return strcmp($a, $b);
}
protected function computeSortString(ListingEntry $entry)
{
if (isset($entry->cache[__CLASS__]['sort'])) {
return $entry->cache[__CLASS__]['sort'];
}
$icons = $this->computeIcons($entry);
$entry->cache[__CLASS__]['sort'] = implode('', array_map(
function($tab)
{
return (empty($tab['icon']) ? 0 : 1);
},
$icons
));;
  • 🔽 Remove this empty statement. 📘

Please register or sign in to reply
return $entry->cache[__CLASS__]['sort'];
}
protected function computeIcons(ListingEntry $entry)
{
if (isset($entry->cache[__CLASS__]['icons'])) {
return $entry->cache[__CLASS__]['icons'];
}
$infos = objects::infos($entry->getTemplatedType());
$icons = array();
/* Main tab is always there */
$pInfos = pluglist::pluginInfos($infos['mainTab']);
$result = '<input type="image" src="'.htmlentities((isset($pInfos['plSmallIcon']) ? $pInfos['plSmallIcon'] : $infos['icon']), ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$infos['mainTab'].'_'.$entry->row.'"/>';
$icons[] = array(
'icon' => (isset($pInfos['plSmallIcon']) ? $pInfos['plSmallIcon'] : $infos['icon']),
'title' => $pInfos['plShortName'],
'tab' => $infos['mainTab'],
);
if (!empty($entry)) {
if ($entry->isTemplate()) {
$attrs = $entry->getTemplatedFields();
......@@ -83,18 +131,23 @@ class PropertiesColumn extends Column
if ($status !== FALSE) {
$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.'"/>';
$icons[] = array(
'icon' => $pInfos['plSmallIcon'],
'title' => $pInfos['plShortName'],
'tab' => $class,
);
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $pInfos['plShortName']." ($class)", 'No icon for');
}
} else {
$result .= '<img src="images/empty.png" alt="" class="optional '.$class.'"/>';
$icons[] = array(
'tab' => $class,
);
}
}
}
return $result;
$entry->cache[__CLASS__]['icons'] = $icons;
return $entry->cache[__CLASS__]['icons'];
}
}
  • SonarQube analysis reported 2 issues

    • 1 major
    • 🔽 1 minor

    Watch the comments in this conversation to review them.

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