PHP Classes

File: src/render/html/view/view-items.php

Recommend this page to a friend!
  Classes of Ar Gabid   Universal PHP Data Grid   src/render/html/view/view-items.php   Download  
File: src/render/html/view/view-items.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Universal PHP Data Grid
Display and process data to edit database records
Author: By
Last change: Update of src/render/html/view/view-items.php
Date: 4 years ago
Size: 1,606 bytes
 

Contents

Class file image Download
<?php

use gdgrid\gd\GridDataFormatter as Format;

/* @var \gdgrid\gd\GridView $this */

$tagAttr = $this->getTagAttributes();

if (
$this->getTemplate() === null)
{
    switch (
$this->getTag())
    {
        case
'ol':
        case
'ul':

           
$t = '<li {attr}>{row}</li>';

            if (
false == isset($tagAttr['class']))

               
$tagAttr['class'] = ['list-unstyled'];

            break;
        case
'div':

           
$t = '<div {attr}>{row}</div>';

            break;
        case
'table':

           
$t = '<tr {attr}><td>{row}</td></tr>';

            if (
false == isset($tagAttr['class']))

               
$tagAttr['class'] = ['table', 'table-striped', 'table-bordered'];

            break;
        default:

           
$t = '{row}';
    }

   
$this->setTemplate($t);
}

$output = $this->getLayout() ?: ($this->getTag() ? '<{tag} {attr}>{rows}</{tag}>' : '{rows}');

$rows = '';

$attr = Format::getAttributes($this->getRowAttributes());

foreach (
$this->getProviderItems() as $i => $item)
{
   
$data = $this->fetchData($item, $i);

   
$tr = [
       
'{attr}' => $attr,
       
'{row}' => null,
    ];

    if (
is_array($data))
    {
        if (isset(
$data['{attr}']) && is_array($data['{attr}']))

           
$data['{attr}'] = Format::getAttributes($data['{attr}']);

       
$tr = array_merge($tr, $data);
    }
    else
    {
       
$tr['{row}'] = $data;
    }

   
$rows .= strtr($this->getTemplate(), $tr);
}

echo
strtr($this->fetchLayout($output), [
   
'{tag}' => $this->getTag(),
   
'{attr}' => Format::getAttributes($tagAttr),
   
'{rows}' => $rows
]);