Management controllers: make format functions first-level
This commit is contained in:
parent
6ca3ee6d9d
commit
9740416cb2
@ -35,18 +35,14 @@ class ManageAlbums extends HTMLController
|
||||
'tag' => [
|
||||
'header' => 'Album',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
||||
'data' => 'tag',
|
||||
],
|
||||
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
||||
'value' => 'tag',
|
||||
],
|
||||
'slug' => [
|
||||
'header' => 'Slug',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
||||
'data' => 'slug',
|
||||
],
|
||||
'link' => BASEURL . '/editalbum/?id={ID_TAG}',
|
||||
'value' => 'slug',
|
||||
],
|
||||
'count' => [
|
||||
'header' => '# Photos',
|
||||
|
@ -38,40 +38,33 @@ class ManageAssets extends HTMLController
|
||||
'checkbox' => [
|
||||
'header' => '<input type="checkbox" id="selectall">',
|
||||
'is_sortable' => false,
|
||||
'format' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
return '<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">';
|
||||
},
|
||||
],
|
||||
'format' => fn($row) =>
|
||||
'<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">',
|
||||
],
|
||||
'thumbnail' => [
|
||||
'header' => ' ',
|
||||
'is_sortable' => false,
|
||||
'cell_class' => 'text-center',
|
||||
'format' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
$asset = Image::byRow($row);
|
||||
$width = $height = 65;
|
||||
if ($asset->isImage())
|
||||
{
|
||||
if ($asset->isPortrait())
|
||||
$width = null;
|
||||
else
|
||||
$height = null;
|
||||
|
||||
$thumb = $asset->getThumbnailUrl($width, $height);
|
||||
}
|
||||
'format' => function($row) {
|
||||
$asset = Image::byRow($row);
|
||||
$width = $height = 65;
|
||||
if ($asset->isImage())
|
||||
{
|
||||
if ($asset->isPortrait())
|
||||
$width = null;
|
||||
else
|
||||
$thumb = BASEURL . '/images/nothumb.svg';
|
||||
$height = null;
|
||||
|
||||
$width = isset($width) ? $width . 'px' : 'auto';
|
||||
$height = isset($height) ? $height . 'px' : 'auto';
|
||||
$thumb = $asset->getThumbnailUrl($width, $height);
|
||||
}
|
||||
else
|
||||
$thumb = BASEURL . '/images/nothumb.svg';
|
||||
|
||||
return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
|
||||
},
|
||||
],
|
||||
$width = isset($width) ? $width . 'px' : 'auto';
|
||||
$height = isset($height) ? $height . 'px' : 'auto';
|
||||
|
||||
return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
|
||||
},
|
||||
],
|
||||
'id_asset' => [
|
||||
'value' => 'id_asset',
|
||||
@ -87,38 +80,29 @@ class ManageAssets extends HTMLController
|
||||
'value' => 'filename',
|
||||
'header' => 'Filename',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'type' => 'value',
|
||||
'link' => BASEURL . '/editasset/?id={ID_ASSET}',
|
||||
'data' => 'filename',
|
||||
],
|
||||
'link' => BASEURL . '/editasset/?id={ID_ASSET}',
|
||||
'value' => 'filename',
|
||||
],
|
||||
'id_user_uploaded' => [
|
||||
'header' => 'User uploaded',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
if (!empty($row['id_user']))
|
||||
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
||||
$row['first_name'] . ' ' . $row['surname']);
|
||||
else
|
||||
return 'n/a';
|
||||
},
|
||||
],
|
||||
'format' => function($row) {
|
||||
if (!empty($row['id_user']))
|
||||
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
||||
$row['first_name'] . ' ' . $row['surname']);
|
||||
else
|
||||
return 'n/a';
|
||||
},
|
||||
],
|
||||
'dimensions' => [
|
||||
'header' => 'Dimensions',
|
||||
'is_sortable' => false,
|
||||
'format' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
if (!empty($row['image_width']))
|
||||
return $row['image_width'] . ' x ' . $row['image_height'];
|
||||
else
|
||||
return 'n/a';
|
||||
},
|
||||
],
|
||||
'format' => function($row) {
|
||||
if (!empty($row['image_width']))
|
||||
return $row['image_width'] . ' x ' . $row['image_height'];
|
||||
else
|
||||
return 'n/a';
|
||||
},
|
||||
],
|
||||
],
|
||||
'default_sort_order' => 'id_asset',
|
||||
|
@ -45,20 +45,17 @@ class ManageErrors extends HTMLController
|
||||
'is_sortable' => true,
|
||||
],
|
||||
'message' => [
|
||||
'format' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
return $row['message'] . '<br>' .
|
||||
'<div><a onclick="this.parentNode.childNodes[1].style.display=\'block\';this.style.display=\'none\';">Show debug info</a>' .
|
||||
'<pre style="display: none">' . htmlspecialchars($row['debug_info']) .
|
||||
'</pre></div>' .
|
||||
'<small><a href="' . BASEURL .
|
||||
htmlspecialchars($row['request_uri']) . '">' .
|
||||
htmlspecialchars($row['request_uri']) . '</a></small>';
|
||||
}
|
||||
],
|
||||
'header' => 'Message / URL',
|
||||
'is_sortable' => false,
|
||||
'format' => function($row) {
|
||||
return $row['message'] . '<br>' .
|
||||
'<div><a onclick="this.parentNode.childNodes[1].style.display=\'block\';this.style.display=\'none\';">Show debug info</a>' .
|
||||
'<pre style="display: none">' . htmlspecialchars($row['debug_info']) .
|
||||
'</pre></div>' .
|
||||
'<small><a href="' . BASEURL .
|
||||
htmlspecialchars($row['request_uri']) . '">' .
|
||||
htmlspecialchars($row['request_uri']) . '</a></small>';
|
||||
},
|
||||
],
|
||||
'file' => [
|
||||
'value' => 'file',
|
||||
@ -89,10 +86,8 @@ class ManageErrors extends HTMLController
|
||||
'uid' => [
|
||||
'header' => 'UID',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'data' => 'id_user',
|
||||
],
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'value' => 'id_user',
|
||||
],
|
||||
],
|
||||
'default_sort_order' => 'id_entry',
|
||||
|
@ -37,32 +37,25 @@ class ManageTags extends HTMLController
|
||||
'tag' => [
|
||||
'header' => 'Tag',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
||||
'data' => 'tag',
|
||||
],
|
||||
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
||||
'value' => 'tag',
|
||||
],
|
||||
'slug' => [
|
||||
'header' => 'Slug',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
||||
'data' => 'slug',
|
||||
],
|
||||
'link' => BASEURL . '/edittag/?id={ID_TAG}',
|
||||
'value' => 'slug',
|
||||
],
|
||||
'id_user_owner' => [
|
||||
'header' => 'Owning user',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
if (!empty($row['id_user']))
|
||||
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
||||
$row['first_name'] . ' ' . $row['surname']);
|
||||
else
|
||||
return 'n/a';
|
||||
},
|
||||
],
|
||||
'format' => function($row) {
|
||||
if (!empty($row['id_user']))
|
||||
return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
|
||||
$row['first_name'] . ' ' . $row['surname']);
|
||||
else
|
||||
return 'n/a';
|
||||
},
|
||||
],
|
||||
'count' => [
|
||||
'header' => 'Cardinality',
|
||||
|
@ -37,26 +37,20 @@ class ManageUsers extends HTMLController
|
||||
'surname' => [
|
||||
'header' => 'Last name',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'data' => 'surname',
|
||||
],
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'value' => 'surname',
|
||||
],
|
||||
'first_name' => [
|
||||
'header' => 'First name',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'data' => 'first_name',
|
||||
],
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'value' => 'first_name',
|
||||
],
|
||||
'slug' => [
|
||||
'header' => 'Slug',
|
||||
'is_sortable' => true,
|
||||
'format' => [
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'data' => 'slug',
|
||||
],
|
||||
'link' => BASEURL . '/edituser/?id={ID_USER}',
|
||||
'value' => 'slug',
|
||||
],
|
||||
'emailaddress' => [
|
||||
'value' => 'emailaddress',
|
||||
@ -82,12 +76,7 @@ class ManageUsers extends HTMLController
|
||||
'is_admin' => [
|
||||
'is_sortable' => true,
|
||||
'header' => 'Admin?',
|
||||
'format' => [
|
||||
'type' => 'function',
|
||||
'data' => function($row) {
|
||||
return $row['is_admin'] ? 'yes' : 'no';
|
||||
}
|
||||
],
|
||||
'format' => fn($row) => $row['is_admin'] ? 'yes' : 'no',
|
||||
],
|
||||
],
|
||||
'default_sort_order' => 'id_user',
|
||||
|
@ -192,7 +192,9 @@ class GenericTable
|
||||
foreach ($options['columns'] as $column)
|
||||
{
|
||||
// Process formatting
|
||||
if (isset($column['format']))
|
||||
if (isset($column['format']) && is_callable($column['format']))
|
||||
$value = $column['format']($row);
|
||||
elseif (isset($column['format']))
|
||||
$value = self::processFormatting($column['format'], $row);
|
||||
else
|
||||
$value = $row[$column['value']];
|
||||
|
Loading…
Reference in New Issue
Block a user