Refactor the GenericTables class #51
@ -35,18 +35,14 @@ class ManageAlbums extends HTMLController
 | 
				
			|||||||
				'tag' => [
 | 
									'tag' => [
 | 
				
			||||||
					'header' => 'Album',
 | 
										'header' => 'Album',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/editalbum/?id={ID_TAG}',
 | 
										'link' => BASEURL . '/editalbum/?id={ID_TAG}',
 | 
				
			||||||
						'data' => 'tag',
 | 
										'value' => 'tag',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'slug' => [
 | 
									'slug' => [
 | 
				
			||||||
					'header' => 'Slug',
 | 
										'header' => 'Slug',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/editalbum/?id={ID_TAG}',
 | 
										'link' => BASEURL . '/editalbum/?id={ID_TAG}',
 | 
				
			||||||
						'data' => 'slug',
 | 
										'value' => 'slug',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'count' => [
 | 
									'count' => [
 | 
				
			||||||
					'header' => '# Photos',
 | 
										'header' => '# Photos',
 | 
				
			||||||
 | 
				
			|||||||
@ -38,20 +38,14 @@ class ManageAssets extends HTMLController
 | 
				
			|||||||
				'checkbox' => [
 | 
									'checkbox' => [
 | 
				
			||||||
					'header' => '<input type="checkbox" id="selectall">',
 | 
										'header' => '<input type="checkbox" id="selectall">',
 | 
				
			||||||
					'is_sortable' => false,
 | 
										'is_sortable' => false,
 | 
				
			||||||
					'format' => [
 | 
										'format' => fn($row) =>
 | 
				
			||||||
						'type' => 'function',
 | 
											'<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">',
 | 
				
			||||||
						'data' => function($row) {
 | 
					 | 
				
			||||||
							return '<input type="checkbox" class="asset_select" name="delete[]" value="' . $row['id_asset'] . '">';
 | 
					 | 
				
			||||||
						},
 | 
					 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'thumbnail' => [
 | 
									'thumbnail' => [
 | 
				
			||||||
					'header' => ' ',
 | 
										'header' => ' ',
 | 
				
			||||||
					'is_sortable' => false,
 | 
										'is_sortable' => false,
 | 
				
			||||||
					'cell_class' => 'text-center',
 | 
										'cell_class' => 'text-center',
 | 
				
			||||||
					'format' => [
 | 
										'format' => function($row) {
 | 
				
			||||||
						'type' => 'function',
 | 
					 | 
				
			||||||
						'data' => function($row) {
 | 
					 | 
				
			||||||
						$asset = Image::byRow($row);
 | 
											$asset = Image::byRow($row);
 | 
				
			||||||
						$width = $height = 65;
 | 
											$width = $height = 65;
 | 
				
			||||||
						if ($asset->isImage())
 | 
											if ($asset->isImage())
 | 
				
			||||||
@ -72,7 +66,6 @@ class ManageAssets extends HTMLController
 | 
				
			|||||||
						return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
 | 
											return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				],
 | 
					 | 
				
			||||||
				'id_asset' => [
 | 
									'id_asset' => [
 | 
				
			||||||
					'value' => 'id_asset',
 | 
										'value' => 'id_asset',
 | 
				
			||||||
					'header' => 'ID',
 | 
										'header' => 'ID',
 | 
				
			||||||
@ -87,18 +80,13 @@ class ManageAssets extends HTMLController
 | 
				
			|||||||
					'value' => 'filename',
 | 
										'value' => 'filename',
 | 
				
			||||||
					'header' => 'Filename',
 | 
										'header' => 'Filename',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
						'type' => 'value',
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/editasset/?id={ID_ASSET}',
 | 
										'link' => BASEURL . '/editasset/?id={ID_ASSET}',
 | 
				
			||||||
						'data' => 'filename',
 | 
										'value' => 'filename',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'id_user_uploaded' => [
 | 
									'id_user_uploaded' => [
 | 
				
			||||||
					'header' => 'User uploaded',
 | 
										'header' => 'User uploaded',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
										'format' => function($row) {
 | 
				
			||||||
						'type' => 'function',
 | 
					 | 
				
			||||||
						'data' => function($row) {
 | 
					 | 
				
			||||||
						if (!empty($row['id_user']))
 | 
											if (!empty($row['id_user']))
 | 
				
			||||||
							return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
 | 
												return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
 | 
				
			||||||
								$row['first_name'] . ' ' . $row['surname']);
 | 
													$row['first_name'] . ' ' . $row['surname']);
 | 
				
			||||||
@ -106,13 +94,10 @@ class ManageAssets extends HTMLController
 | 
				
			|||||||
							return 'n/a';
 | 
												return 'n/a';
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				],
 | 
					 | 
				
			||||||
				'dimensions' => [
 | 
									'dimensions' => [
 | 
				
			||||||
					'header' => 'Dimensions',
 | 
										'header' => 'Dimensions',
 | 
				
			||||||
					'is_sortable' => false,
 | 
										'is_sortable' => false,
 | 
				
			||||||
					'format' => [
 | 
										'format' => function($row) {
 | 
				
			||||||
						'type' => 'function',
 | 
					 | 
				
			||||||
						'data' => function($row) {
 | 
					 | 
				
			||||||
						if (!empty($row['image_width']))
 | 
											if (!empty($row['image_width']))
 | 
				
			||||||
							return $row['image_width'] . ' x ' . $row['image_height'];
 | 
												return $row['image_width'] . ' x ' . $row['image_height'];
 | 
				
			||||||
						else
 | 
											else
 | 
				
			||||||
@ -120,7 +105,6 @@ class ManageAssets extends HTMLController
 | 
				
			|||||||
					},
 | 
										},
 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
			],
 | 
								],
 | 
				
			||||||
			],
 | 
					 | 
				
			||||||
			'default_sort_order' => 'id_asset',
 | 
								'default_sort_order' => 'id_asset',
 | 
				
			||||||
			'default_sort_direction' => 'down',
 | 
								'default_sort_direction' => 'down',
 | 
				
			||||||
			'start' => $_GET['start'] ?? 0,
 | 
								'start' => $_GET['start'] ?? 0,
 | 
				
			||||||
 | 
				
			|||||||
@ -45,9 +45,9 @@ class ManageErrors extends HTMLController
 | 
				
			|||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'message' => [
 | 
									'message' => [
 | 
				
			||||||
					'format' => [
 | 
										'header' => 'Message / URL',
 | 
				
			||||||
						'type' => 'function',
 | 
										'is_sortable' => false,
 | 
				
			||||||
						'data' => function($row) {
 | 
										'format' => function($row) {
 | 
				
			||||||
						return $row['message'] . '<br>' .
 | 
											return $row['message'] . '<br>' .
 | 
				
			||||||
							'<div><a onclick="this.parentNode.childNodes[1].style.display=\'block\';this.style.display=\'none\';">Show debug info</a>' .
 | 
												'<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 style="display: none">' . htmlspecialchars($row['debug_info']) .
 | 
				
			||||||
@ -55,10 +55,7 @@ class ManageErrors extends HTMLController
 | 
				
			|||||||
							'<small><a href="' . BASEURL .
 | 
												'<small><a href="' . BASEURL .
 | 
				
			||||||
								htmlspecialchars($row['request_uri']) . '">' .
 | 
													htmlspecialchars($row['request_uri']) . '">' .
 | 
				
			||||||
								htmlspecialchars($row['request_uri']) . '</a></small>';
 | 
													htmlspecialchars($row['request_uri']) . '</a></small>';
 | 
				
			||||||
						}
 | 
										},
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
					'header' => 'Message / URL',
 | 
					 | 
				
			||||||
					'is_sortable' => false,
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'file' => [
 | 
									'file' => [
 | 
				
			||||||
					'value' => 'file',
 | 
										'value' => 'file',
 | 
				
			||||||
@ -89,10 +86,8 @@ class ManageErrors extends HTMLController
 | 
				
			|||||||
				'uid' => [
 | 
									'uid' => [
 | 
				
			||||||
					'header' => 'UID',
 | 
										'header' => 'UID',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
										'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
				
			||||||
						'data' => 'id_user',
 | 
										'value' => 'id_user',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
			],
 | 
								],
 | 
				
			||||||
			'default_sort_order' => 'id_entry',
 | 
								'default_sort_order' => 'id_entry',
 | 
				
			||||||
 | 
				
			|||||||
@ -37,25 +37,19 @@ class ManageTags extends HTMLController
 | 
				
			|||||||
				'tag' => [
 | 
									'tag' => [
 | 
				
			||||||
					'header' => 'Tag',
 | 
										'header' => 'Tag',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/edittag/?id={ID_TAG}',
 | 
										'link' => BASEURL . '/edittag/?id={ID_TAG}',
 | 
				
			||||||
						'data' => 'tag',
 | 
										'value' => 'tag',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'slug' => [
 | 
									'slug' => [
 | 
				
			||||||
					'header' => 'Slug',
 | 
										'header' => 'Slug',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/edittag/?id={ID_TAG}',
 | 
										'link' => BASEURL . '/edittag/?id={ID_TAG}',
 | 
				
			||||||
						'data' => 'slug',
 | 
										'value' => 'slug',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'id_user_owner' => [
 | 
									'id_user_owner' => [
 | 
				
			||||||
					'header' => 'Owning user',
 | 
										'header' => 'Owning user',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
										'format' => function($row) {
 | 
				
			||||||
						'type' => 'function',
 | 
					 | 
				
			||||||
						'data' => function($row) {
 | 
					 | 
				
			||||||
						if (!empty($row['id_user']))
 | 
											if (!empty($row['id_user']))
 | 
				
			||||||
							return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
 | 
												return sprintf('<a href="%s/edituser/?id=%d">%s</a>', BASEURL, $row['id_user'],
 | 
				
			||||||
								$row['first_name'] . ' ' . $row['surname']);
 | 
													$row['first_name'] . ' ' . $row['surname']);
 | 
				
			||||||
@ -63,7 +57,6 @@ class ManageTags extends HTMLController
 | 
				
			|||||||
							return 'n/a';
 | 
												return 'n/a';
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				],
 | 
					 | 
				
			||||||
				'count' => [
 | 
									'count' => [
 | 
				
			||||||
					'header' => 'Cardinality',
 | 
										'header' => 'Cardinality',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
 | 
				
			|||||||
@ -37,26 +37,20 @@ class ManageUsers extends HTMLController
 | 
				
			|||||||
				'surname' => [
 | 
									'surname' => [
 | 
				
			||||||
					'header' => 'Last name',
 | 
										'header' => 'Last name',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
										'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
				
			||||||
						'data' => 'surname',
 | 
										'value' => 'surname',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'first_name' => [
 | 
									'first_name' => [
 | 
				
			||||||
					'header' => 'First name',
 | 
										'header' => 'First name',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
										'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
				
			||||||
						'data' => 'first_name',
 | 
										'value' => 'first_name',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'slug' => [
 | 
									'slug' => [
 | 
				
			||||||
					'header' => 'Slug',
 | 
										'header' => 'Slug',
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'format' => [
 | 
					 | 
				
			||||||
					'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
										'link' => BASEURL . '/edituser/?id={ID_USER}',
 | 
				
			||||||
						'data' => 'slug',
 | 
										'value' => 'slug',
 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
				'emailaddress' => [
 | 
									'emailaddress' => [
 | 
				
			||||||
					'value' => 'emailaddress',
 | 
										'value' => 'emailaddress',
 | 
				
			||||||
@ -82,12 +76,7 @@ class ManageUsers extends HTMLController
 | 
				
			|||||||
				'is_admin' => [
 | 
									'is_admin' => [
 | 
				
			||||||
					'is_sortable' => true,
 | 
										'is_sortable' => true,
 | 
				
			||||||
					'header' => 'Admin?',
 | 
										'header' => 'Admin?',
 | 
				
			||||||
					'format' => [
 | 
										'format' => fn($row) => $row['is_admin'] ? 'yes' : 'no',
 | 
				
			||||||
						'type' => 'function',
 | 
					 | 
				
			||||||
						'data' => function($row) {
 | 
					 | 
				
			||||||
							return $row['is_admin'] ? 'yes' : 'no';
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
					],
 | 
					 | 
				
			||||||
				],
 | 
									],
 | 
				
			||||||
			],
 | 
								],
 | 
				
			||||||
			'default_sort_order' => 'id_user',
 | 
								'default_sort_order' => 'id_user',
 | 
				
			||||||
 | 
				
			|||||||
@ -192,7 +192,9 @@ class GenericTable
 | 
				
			|||||||
			foreach ($options['columns'] as $column)
 | 
								foreach ($options['columns'] as $column)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				// Process formatting
 | 
									// 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);
 | 
										$value = self::processFormatting($column['format'], $row);
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
					$value = $row[$column['value']];
 | 
										$value = $row[$column['value']];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user